Ruby problems
in array_runs.rb:
-
Coding Problem
Given an array of unsorted positive ints, write a function that finds runs of 3 consecutive numbers (ascending or descending) and returns the indices where such runs begin. If no such runs are found, return null.
function findConsecutiveRuns(input:Array):Array Example: [1, 2, 3, 5, 10, 9, 8, 9, 10, 11, 7] would return [0, 4, 6, 7]
TO RUN: run array_runs.rb with csv of integers as argument
ex: ruby array_runs.rb 1,2,3,5,10,9,8,9,10,11,7
-
Write a backend library for auction house for their online auction system so it supports the following operations (assume that we have a in memory key-value store lib and a unique id generator available)
Auctioneer adds an item that can be auctioned. An item has a unique name and reserved price
Auctioneer starts an auction on an item
Participants submit bids to an auction, a new bid has to have a price higher than the current highest bid otherwise it’s not allowed.
Auctioneer calls the auction (when s/he makes the judgement on her own that there will be no more higher bids coming in). If the current highest bid is higher than the reserved price of the item, the auction is deemed as a success otherwise it’s marked as failure. The item sold should be no longer available for future auctions.
Participant/Auctioneer queries the latest action of an item by item name. The library should return the status of the auction if there is any, if the item is sold, it should return the information regarding the price sold and to whom it was sold to.
ASSUMPTIONS/ADJUSTMENTS: I’m not validating item name uniqueness because an item can have multiple auctions and we’re not storing items separately from auctions. I used SecureRandom to generate guids for things. I also stored info on auctions in a simple hash in AuctionHouse. I’m also returning leading bid info on open auctions as well as winning bids on closed ones. Test is not in RSpec format :).
TO TEST: run auction_test.rb