Tag: javascript

  • Sparse Arrays – Hackerrank medium problem in JS solved using HashMap

    https://www.hackerrank.com/challenges/sparse-arrays/problem The idea is to iterate over input data and put it into HashMap with keys being available strings and values being the number of times this string is present in the input. Time complexity is O(n) and space complexity O(n)

  • Clone Undirected Graph with Javascript

    A question that I got asked on the interview at Facebook on 2016 that I wasn’t able to finish coding within interview time frame. Finally got a chance to put it into code. I used a LeetCode as a JS platform to test a code: https://leetcode.com/problems/clone-graph/description/ /** * Definition for undirected graph. * function UndirectedGraphNode(label)…

  • 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];…