This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Problem: Employees-Friends-Divisions Association Mapping | |
// Input 1. employeesInput: 3 comma separated data fields: id, name, division | |
// Input 2. friendsInput: 2 comma separated data fields: ids of 2 employees who are friends | |
// | |
// Task 1: Associate each employee with his list of friends | |
// Task 2: Count the following: | |
// 1. The number of employees in each division | |
// 2. The number of employees per division who have friends outside of his division |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Problem: Find the rectangles inside the input image array | |
// Input: An array representing an image, where 1 represents pixel on, 0 off | |
// Task 1: Find the rectangle (top-left coordinate, width, height) in an array containing a single rectangle | |
// Task 2: Find all the rectangles inside an array containing multiple rectangles | |
// image1 expected result: top-left = (2,3), width = 4, height = 3 | |
let image1 = [ | |
[1,1,1,1,1,1,1,1], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Stack<Element> { | |
var items = [Element]() | |
var count : Int { | |
return items.count | |
} | |
mutating func push(_ item: Element) { | |
items.append(item) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using ICSharpCode.SharpZipLib.Tar; | |
using ICSharpCode.SharpZipLib.GZip; | |
public class RouteEncoder | |
{ | |
private static ILogger Logger = LoggerExtensions.GetLogger(nameof(RouteEncoder)); | |
public void EncodeRoute(Route route, Stream responseStream) | |
{ | |
string xmlContent = ComposeRouteXMLContent(route.DestinationLocations); | |
if (xmlContent != null) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using ICSharpCode.SharpZipLib.GZip; | |
using ICSharpCode.SharpZipLib.Tar; | |
public struct WayPoint | |
{ | |
public string address1; | |
public string address2; | |
public GeoCoordinate geoCoord; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
class TimeUtility { | |
static let iso8601DateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ" | |
static let timeZoneOffsetFormat = "ZZZZZ" | |
static let en_USNSLocaleID = "en_US_POSIX" | |
static func covertToISO8601String(_ date: Foundation.Date) -> String { | |
let dateFormatter = DateFormatter() | |
dateFormatter.locale = Foundation.Locale(identifier: TimeUtility.en_USNSLocaleID) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
enum TripType : CustomStringConvertible, Equatable { | |
case user | |
case calendar(CalendarTripSubtype) | |
case predicted(PredictedTripSubtype) | |
case shared | |
case unknown | |
static func fromString(_ input: String?) -> TripType { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ObjectMapper | |
func handleResponse(_ responseObject: LocationTripResponseMappable, source: AnalyticsConstants.LOCATION_TRIP_SYNC_SOURCE, requestParameters: [String:Any]) { | |
let responseObject = createMockResponse() | |
... | |
} | |
fileprivate func createMockResponse() -> LocationTripResponseMappable { | |
let id1 = "id1" | |
let id2 = "id2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1.361s | |
func applyLimit(toData data: [EkEventDao]) -> [EkEventDao] { | |
var datesDict:[String:Int] = [:] | |
var limitedData: [EkEventDao] = [] | |
for datum in data { | |
let dateKey = datum.startDate.startOfDay.description | |
let value = datesDict[dateKey] | |
if value == nil { datesDict[dateKey] = 0 } | |
guard datesDict[dateKey]!<Const.MAX_ENTRIES_PER_DAY else { continue } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
protocol DelayerProtocol { | |
func delay(forSeconds seconds: Double, closure: () -> Void) | |
} | |
class Delayer: DelayerProtocol { | |
func delay(forSeconds seconds: Double, closure: () -> Void) { | |
let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(seconds * Double(NSEC_PER_SEC))) | |
dispatch_after(delayTime, dispatch_get_main_queue()) { |