All tags

Longest Common Prefix

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 “".

Example 1:

Input: [“flower”,“flow”,“flight”] Output: “fl”

Example 2:

Input: [“dog”,“racecar”,“car”] Output: "” Explanation: There is no common prefix among the input strings.

Note:

All given inputs are in lowercase letters a-z.

Solution

Factorial

Factorial of a non-negative integer, is multiplication of all integers smaller than or equal to n. For example factorial of 6 is 65432*1 which is 720.

Capitalization

Given a phrase, capitalize every word.

Relative Sort Array

Given two arrays arr1 and arr2, the elements of arr2 are distinct, and all elements in arr2 are also in arr1.

Roman to Integer

Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.

Determine Greatest Common Divisor

The greatest common divisor (GCD), also called highest common factor (HCF) of N numbers is the largest positive integer that divides all numbers without giving a remainder.

Merge Sorted Array

Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.

Defanging an Ip Address

Given a valid (IPv4) IP address, return a defanged version of that IP address.

Maximum Depth of N Ary Tree

Given a n-ary tree, find its maximum depth.

Array Chunking

Given an array and a size, split the array items into a list of arrays of the given size.

Staircase

Consider a staircase of size n=4: # ## ### #### Observe that its base and height are both equal to , and the image is drawn using # symbols and spaces.

Fibonacci

Implement a function that returns the fibonacci number at a given index. Implement this memoized.