Category: Other

  • Coding algorithm helper

    Tree Traversals. Depth-first: Inorder, pre-order, post-order. Bread-first.

  • Surrounding regions using flash flood algorithm

    Set all of the O to – across the board For each side find adjacent – and change them to Os using flash flood algorithm Change all of the remaining – to X The complexity of the above solution is O(m*n)

  • Dynamic Programming

    A list of problems that will let you learn dynamic programming Maximum Subarray Can be solved with Kadane algorithm Maximum Product Subarray Instead of using one variable to store the max we can use two variables to store max and min and flip them whenever we would meet a negative value

  • Find Peak Element with JS

    A peak element is an element that is strictly greater than its neighbors. Given an integer array nums, find a peak element, and return its index. If the array contains multiple peaks, return the index to any of the peaks. You may imagine that nums[-1] = nums[n] = -∞. An interesting challenge to solve the following problem within O(log(n))…

  • Reduce Array Size to The Half with JS solved using dictionary

    Given an array arr.  You can choose a set of integers and remove all the occurrences of these integers in the array. Return the minimum size of the set so that at least half of the integers of the array are removed. Solution iterate over an array and store the number of repetitive integers in the dictionary generate an array…

  • Lowest Common Ancestor in a Binary Tree LeetCode problem in JS solved with comparing vector path to each node

    Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes p and q as the lowest node in T that has both p and q as descendants (where we allow a…

  • MyCalendar LeetCode problem in JS solved with double arrays

    Problem defenition Implement a MyCalendar class to store your events. A new event can be added if adding the event will not cause a double booking. Your class will have the method, book(int start, int end). Formally, this represents a booking on the half open interval [start, end), the range of real numbers x such that start <= x < end. A double…

  • Finding a next lucky number with C++.

    This is an easy task for Monday from Week of Code at Hackerrank. The task is to find a next lucky number based on given 6 digit integer. #include <bits/stdc++.h> #include <string> using namespace std; bool isLucky(int x) { int digit6 = x % 10; int digit5 = (int)((x % 100) / 10); int digit4…

  • Singleton in iOS

    Recommended way of creating singleton according to Apple is in the following way: + (AKMySingleton *)sharedInstance { static AKMySingleton *_sharedInstance = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ _sharedInstance = [[[self class] alloc] init]; }); return _sharedInstance; } Dispatch-once is a synchronous operation that will make sure that there are no multiple threads that are trying…

  • Recursively revert an array in Objective C

    It’s a question that my fried received on a phone interview with one of the tech companies from West Coast Let’s do it! We will create a function reverseAnArray that takes a NSMutableArray and return void. +(void) reverseAnArray:(NSMutableArray *)input; 1. Set up a base – once we reach the end of the array we will…