Category: iOS

  • Find a second largest number in array with Javascript

    Back to the simple coding questions. This time with javascript – it seems the easiest language to test with. Code for the problem can be run over here: http://js.do/code/svetliy-second-largest var first_largest; var second_largess; function large(a_list){ if (a_list.length == 0 || a_list.length == 1) return “None”; if (a_list[0] > a_list[1]){ first_largest = a_list[0]; second_largest = a_list[1];…

  • Missing Numbers Hackerrank problem with C++

    https://www.hackerrank.com/challenges/missing-numbers/problem Solved using sorting two arrays, finding missing number in the loop and putting them in the set. #include <cmath> #include <cstdio> #include <vector> #include <set> #include <iostream> #include <algorithm> using namespace std; set<int> findMissing(int n, vector <int> ar1, vector <int> ar2) { // using default comparison (operator <): sort (ar1.begin(), ar1.end()); sort (ar2.begin(), ar2.end());…

  • Insert a node into Linked list with C++

    Check if Linked List is null and just create a Node. Otherwise, run to the end of the linked list and insert a node at the end. /* Insert Node at the end of a linked list head pointer input could be NULL as well for empty list Node is defined as struct Node {…

  • 2D Array easy hackerrank challenge in Swift 3

    https://www.hackerrank.com/challenges/2d-array Had to refresh memory how to parse input from Hackerrank in Swift 3. import Foundation; func run() { var arr : [[Int]] = [] for _ in 0 … 5 { let numbers = readLine()!.components(separatedBy: [” “]).map { Int($0)! } arr.append(numbers); } var maxSum = calculateHourglass(arr: arr, x: 0, y: 0) for i in…

  • How to hide strange unwanted Xcode 8 logs

    by

    in

    Running app in the simulator in a new shine xcode 8 noticed that there are a lot of extra information that is coming from the logs. To disable it and see regular logs do the following: 1. Click on your project name and select “Edit Scheme” 2. Add environment variable OS_ACTIVITY_MODE and set it to…

  • Problem Given an array of elements, find the maximum possible sum of a Contiguous subarray Non-contiguous (not necessarily contiguous) subarray. Empty subarrays/subsequences should not be considered. Input Format First line of the input has an integer . cases follow. Each test case begins with an integer . In the next line, integers follow representing the…

  • Diagonal Difference from HackerRank in Swift

    Problem Given a square matrix of size , calculate the absolute difference between the sums of its diagonals. Input Format The first line contains a single integer, . The next lines denote the matrix’s rows, with each line containing space-separated integers describing the columns. Output Format Print the absolute difference between the two sums of…

  • Google phone interview for iOS mobile developer position

    An outline of google phone interview: Question 1 // Create a function that takes int numbers[1000] and sorts it into ascending order (lowest to highest) I asked an interviewer if bubble sort is ok, or does he wants something more complex. He said that bubble sort is good enough. I also talked about the complexity,…

  • Flatten a recursive Linked List in Objective-C

    Given a linked list, where each node’s value can itself be a linked list (a recursive linked list), write a function that flattens it. Final code at Github Pretty difficult coding questions. First I tried a recursive solution that for some reason wasn’t working for all cases and then I came up with this one.…

  • Sherlock and Array – Question from hackerrank

    Just finish a fun question from Hackerrank: Sherlock and Array Question description: Watson gives Sherlock an array AA of length NN. Then he asks him to determine if there exists an element in the array such that the sum of the elements on its left is equal to the sum of the elements on its…