Longest Common Prefix
Problem Statement Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string “”. Examples Solution
Use the search below to find our solutions for selected questions!
Problem Statement Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string “”. Examples Solution
Problem Statement Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[‘ and ‘]’, determine if the input string is valid. An input string is valid if: Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order. Note that an empty string is also considered valid. . . . Read more
Problem Statement Given a directory change command cd a/b/../c/d/e/../../ output the visit count of each directory such as: {a=2, b=1, c=2, d=2, e=1}. Solution
Problem Statement Given m balls and n bin, find out how many ways exist to assign the balls to then bins. Note: the buckets have no order. That is, (1,2,3) and (3,2,1) are considered the same. Example Solution This can be solved using dynamic programming. The solution builds up upon . . . Read more
Problem Statement Given a weighted Directed Acyclic Graphs (DAG), find the shortest path to a particular point from the given starting point. One thing you can do is apply an O(N*N) algorithm and find the shortest distance by calculating all the distances from each node to every other node. As . . . Read more
Problem Statement A and B are playing a game. At the beginning there are n coins. Given two more numbers x and y. In each move a player can pick x or y or 1 coins. A always starts the game. The player who picks the last coin wins the game. For . . . Read more
Problem Statement Consider the following two rules that are to be applied to strings over the alphabets: [‘a’, ‘b’, ‘c’, ‘d’] Replace each ‘a’ with ‘dd’ Delete each ‘b’ Solution
Problem Statement There is an m by n grid with a ball. Given the start coordinate (i,j) of the ball, you can move the ball to adjacent cell or cross the grid boundary in four directions (up, down, left, right). However, you can at most move N times. Find out . . . Read more
Problem Statement A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked ‘Finish’ . . . Read more
Problem Statement We have two integer sequences A and B of the same non-zero length. We are allowed to swap elements A[i] and B[i]. Note that both elements are in the same index position in their respective sequences. At the end of some number of swaps, A and B are . . . Read more