Interview Handbook

  • Longest Common Prefix – Leetcode #14

    Problem Statement This problem is from Leetcode – Longest Common Prefix. The problem statement is as below: Given an array of strings, return the longest common prefix. If none, return an empty string. Solution Lets see the brute force approach: Lets see the code sample below: This code returns the following output: You can check…

    Read More

  • Palindrome Number – Leetcode #9

    Problem Statement This problem is from Leetcode – Palindrome Number. The problem statement in short is as below: Check if an integer x is a palindrome; return true if it is, false if not. SOLUTION In this question we are given an integer. We need to check if its a palindrome or not. Approach Lets…

    Read More

  • Two Sum Problem – Leetcode #1

    Problem Statement This problem is from Leetcode – Two Sum Problem. The problem statement is as below: Given an array and a target, return indices of two numbers that add up to the target. SOLUTION This question is asking us to find two numbers in the given array nums which add up to the given…

    Read More

  • Longest Uniform Sub-String

    Problem Statement Given a string, find the longest uniform sub-string in it. Return the repeating character and the number of times it repeats. Solution Let us take an example string like “abcdddss“. The question is asking us to return the longest sub-string with the same characters. In this case the longest uniform sub-string is “ddd”.…

    Read More

  • First Non-Repeating Character

    Problem Statement Given an input string, find the first non-repeating character in it. Solution Let us take an example string like “aabccdeff“. The question is asking us to return the first character that does not repeat. In this case the first non-repeating character is “b“ Approach Declare a hashmap with Character as key and Boolean…

    Read More

  • The Two Egg Problem

    Problem Statement The two egg problem is as follows: there is a building with 100 floors. You are given 2 identical eggs. How do you use 2 eggs to find the threshold floor, where the egg will definitely break from any floor above floor N, including floor N itself. Solution Note that: Approach – 1…

    Read More