# Technical Interview Questions and Solutions

Browse our database of interview questions and full-length solutions from top companies

## Data Structures and Algorithms

### [Binary Array Partition](/content/questions/binary-array-partition/index.html)
Given an array Z of 0s and 1s, divide the array into 3 non-empty parts, such that all of these parts represent the same binary value.

### [Print Folder Structure](/content/questions/print-folder-structure/index.html)
Given a list of file paths, print all of the files in each of the folders.

### [Image Filter Service](/content/questions/image-filter-service/index.html)
Create a service that allows users to upload an image and apply filters and then sends users a link to download their filtered image.

### [Permutation in String](/content/questions/permutation-in-string/index.html)
Given two strings s1 and s2, return true if s2 contains a permutation of s1, or false otherwise.

### [Maximum Subarray](/content/questions/maximum-subarray/index.html)
Given an integer array nums, find the subarray with the largest sum, and return its sum.

### [Build a Max Heap From an Array](/content/questions/build-a-max-heap/index.html)
Given an array of integers, transform the array in-place to a max heap.

### [Subarray Sum Equals K](/content/questions/subarray-sum-equals-k/index.html)
Given an unsorted array of integers and an integer k, find the number of subarrays whose sum equals k.

### [Odd Even Linked List](/content/questions/odd-even-linked-list/index.html)
Given the head of a singly linked list, group all the nodes with odd indices together followed by the nodes with even indices, and return the reordered list.

### [Generate Parentheses](/content/questions/generate-parentheses/index.html)
Given `n` pairs of parentheses, write a function to generate all combinations of well-formed parentheses.

### [Longest Substring Without Repeating Characters](/content/questions/longest-substring-without-repeating-characters/index.html)
Given a string s, find the length of the longest substring without repeating characters.

### [Even Odd Tree](/content/questions/even-odd-tree/index.html)
Given a tree, verify that on even levels, all values in the level are strictly increasing and even. On odd levels, verify all values in the level are strictly decreasing and odd.

### [Remove Nth Node from End of List](/content/questions/remove-nth-node/index.html)
Given the head of a linked list, remove the nth node from the end of the list and return its head.

### [Employee Hierarchy](/content/questions/employee-hierarchy/index.html)
Given an array of employee IDs including who they report to, write a function to calculate the score for a given employee.

### [Kth Smallest Element](/content/questions/kth-smallest-element/index.html)
Given an integer array and an integer k, return the kth smallest element in the array.

### [Three Sum](/content/questions/three-sum/index.html)
Given an array of integers, return an array of triplets such that i != j != k and nums[i] + nums[j] + nums[k] = 0.

### [Copy List With Random Pointers](/content/questions/copy-list-with-random-pointers/index.html)
Given a linked list with nodes that have an additional pointer referring to another node in the list, return a deep copy of the list.

### [Reverse Words in a String](/content/questions/reverse-words-in-a-string/index.html)
Given an input string `s`, reverse the order of the words without reversing the words themselves.

### [Walls and Gates](/content/questions/walls-and-gates/index.html)
You are given a m x n 2D grid initialized with these three possible values. Fill each empty room with the distance to its nearest gate.

### [File Parsing](/content/questions/file-parsing/index.html)
Given an inefficient file structure, how would you store data to efficiently look up the query? How would you alter this if you had many computers available?

### [Reverse Nodes in k-Group](/content/questions/reverse-nodes-in-k-group/index.html)
Given the head of a linked list, reverse the nodes of the list k at a time, and return the modified list.

### [Palindrome Generator](/content/questions/palindrome-generator/index.html)
Print out all 8-digit palindromes. Limitation: We can't use string manipulation.

### [Valid Palindrome](/content/questions/valid-palindrome/index.html)
Determine if this string, after removing any one character, can become a palindrome. If possible return true, otherwise return false.

### [Right View Of Binary Tree](/content/questions/right-view-of-binary-tree/index.html)
Given the root of a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.

### [Fruit into Baskets](/content/questions/fruit-into-baskets/index.html)
Given a sequence of fruit trees represented as an array of strings. Return the maximum number of fruit trees you can pick from given you can only have one type of fruit in each basket and once you start picking you can't skip a tree and then keep picking.

### [Decode String](/content/questions/decode-string/index.html)
Given an encoded string, return its decoded string.

### [Currency Conversion](/content/questions/currency-conversion/index.html)
Given a set of parameters, find the conversion rate that maps to the 'from' currency to the 'to' currency from every single query. Your return value should be a number.

### [Reverse a Linked List](/content/questions/reverse-linked-list/index.html)
Given the head of a linked list, reverse the list and return the new head.

### [XML Parser](/content/questions/xml-parser/index.html)
Write an XML parser and formatter.

### [LRU Cache](/content/questions/lru-cache/index.html)
Implement an LRU Cache

### [Count Complete Tree Nodes](/content/questions/count-complete-tree-nodes/index.html)
Given the root of a complete binary tree, return the number of nodes in the tree.

### [Sum Root to Leaf Numbers](/content/questions/sum-root-to-leaf-numbers/index.html)
You are given the root of a binary tree containing digits from 0 to 9 only. Each root-to-leaf path in the tree represents a number, for example, the root-to-leaf path 1 -> 2 -> 3 represents the number 123. Return the total sum of all root-to-leaf numbers.

### [Container With the Most Water](/content/questions/container-with-most-water/index.html)
Given n non-negative integers, find two lines that form a container that can hold the most amount of water.

### [Partition List](/content/questions/partition-list/index.html)
Given a list of integers L and a number K, write a function that reorganizes L into three partitions: elements less than K, elements equal to K, and elements greater than K. No additional lists may be used.

### [K Largest Elements](/content/questions/k-largest-elements/index.html)
Write an efficient program for printing k largest elements in an array. Largest elements are returned in order largest to smallest.

### [Number of Subarrays with Bounded Maximum](/content/questions/number-of-subarrays-with-bounded-maximum/index.html)
Given an integer array nums and two integers left and right, return the number of contiguous non-empty subarrays such that the value of the maximum array element in that subarray is in the range [left, right].

### [Shuffle String](/content/questions/shuffle-string/index.html)
Write a function that takes a string as an input and returns a shuffled version of that string then write another function to analyze how well it was shuffled.

### [Partition Equal Subset Sum](/content/questions/partition-equal-subset-sum/index.html)
Given an array of positive numbers, determine if the array can be split such that the two partition sums are equal.

### [Longest Palindromic Substring](/content/questions/longest-palindromic-substring/index.html)
Given a string s, return the longest palindromic substring in s.

### [Partition to K Equal Sum Subsets](/content/questions/partition-to-k-equal-sum-subsets/index.html)
Given an integer array nums and an integer k, return true if it is possible to divide this array into k non-empty subsets whose sums are all equal.

### [Integer Replacement](/content/questions/integer-replacement/index.html)
Given an integer as an input, replace all the digits ‘0’ with ‘5’ in the integer.

### [Confusing Number](/content/questions/confusing-number/index.html)
Write a function that, given a room with 800 BIDDERS, identifies all the confusable numbers.

### [Design WhatsApp](/content/questions/design-whatsapp/index.html)
Design a message app system and client (e.g. WhatsApp) supporting a list of requirements.

### [Binary Tree Upside Down](/content/questions/binary-tree-upside-down/index.html)
Given a binary tree where every node has either 0 or 2 children and every right node is a leaf node, flip it upside down turning it into a binary tree where all left nodes are leaf nodes.

### [Lucky Numbers in a Matrix](/content/questions/lucky-numbers-in-a-matrix/index.html)
Given an m x n matrix of distinct numbers, return all lucky numbers in the matrix in any order.

### [Longest Substring with At Most K Distinct Characters](/content/questions/longest-substring-with-at-most-k-distinct-characters/index.html)
Given a string, find the length of the longest substring in it with no more than K distinct characters.

### [Intersection of Linked List](/content/questions/intersection-of-linked-list/index.html)
Given the heads of two singly linked-lists headA and headB, return the node at which the two lists intersect.

### [Regular Expression Matching](/content/questions/regular-expression-matching/index.html)
Given an input string (s) and a pattern (p), implement regular expression matching with support for '.' and '*'.
*
'.' Matches any single character.
'*' Matches zero or more of the preceding element.

### [Design a Free Food App](/content/questions/design-a-free-food-app/index.html)
Design the service for an app that supports distributing 6 million burgers in 10 minutes.

### [Prefix Pairs](/content/questions/prefix-pairs/index.html)
Given a list of words, match all words with other words from the list that are a prefix for the word.

### [Find Leaves of a Binary Tree](/content/questions/find-leaves-of-binary-tree/index.html)
Given a binary tree, extract all the leaves in repeated succession into a list of lists by starting at the bottom and working your way upwards.

### [Minimum Cost to Construct String](/content/questions/minimum-cost-to-construct-string/index.html)
Given a 2-D integer array mapping the letters ABCD and their costs.

Calculate the smallest cost to make a string of length n.

### [Infinite Binary Print](/content/questions/infinite-binary-print/index.html)
Print out all numbers in binary, preserving leading zeros.

### [Top K Frequent Elements](/content/questions/top-k-frequent-elements/index.html)
Given a non-empty array of integers, return the k most frequent elements.

### [Two Sum](/content/questions/two-sum/index.html)
Given an array of integers, return the indices of the two numbers that add up to a given target.

### [Most Frequent Element in an Array](/content/questions/most-frequent-element-in-an-array/index.html)
Given an array of integers, find the most frequent element in the array. Write a method that takes an array of integers and returns an integer. If there is a tie, you can just return any.

### [Find Peak Element in a 2D Array](/content/questions/find-peak-element/index.html)
Given a two-dimensional binary matrix where 1 represents water and 0 represents land, mutate the matrix in place and return the matrix with the highest peak maximized.

### [Simplify Path](/content/questions/simplify-path/index.html)
You are given a path to a file as a string. The path can contain the symbols: ".." for the parent directory and "." for the current directory. Convert the path into its simplified form.

### [Insert Delete getRandom O(1)](/content/questions/insert-delete-get-random-o-1/index.html)
Design and implement an efficient sampler that works in average O(1) time complexity.

### [Recover Binary Search Tree](/content/questions/recover-binary-search-tree/index.html)
Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure.

### [Alien Dictionary](/content/questions/alien-dictionary/index.html)
You are given a list of lexicographically sorted words from an alien language. This language has a unique order. Return the alphabetical order of all the letters found in the list of words.

### [Transformation Dictionary](/content/questions/transformation-dictionary/index.html)
Given a dictionary of words, determine whether it is possible to transform a given word into another with a fixed number of characters.

### [Split Array Largest Sum](/content/questions/split-array-largest-sum/index.html)
Given an integer array nums and an integer k, split nums into k non-empty subarrays such that the largest sum of any subarray is minimized. Return the minimized largest sum of the split.

### [Longest Increasing Path in a Matrix](/content/questions/longest-increasing-path-in-a-matrix/index.html)
Given an m x n integers matrix, return the length of the longest increasing path in the matrix. You may only move up, down, left, or right.

### [Design LeetCode](/content/questions/design-leetcode/index.html)
Design a coding competition platform with a leaderboard and execution environment.

### [Reverse String](/content/questions/reverse-string/index.html)
Write a program to reverse the given string.

### [Meeting Rooms](/content/questions/meeting-rooms/index.html)
Given a list of meetings, represented as tuples with a start and an end time, determine the minimum number of rooms required to schedule all the meetings.

### [Minimum Window Substring](/content/questions/minimum-window-substring/index.html)
Given two strings s and t of lengths m and n respectively, return the minimum window substring of s such that every character in t (including duplicates) is included in the window.

### [K Closest Points To Origin](/content/questions/k-closest-points-to-origin/index.html)
Given a list of tuples that represent (X, Y) coordinates on an XY plane and an integer K, return a list of the K-closest points to the origin (0, 0).

### [Longest Common Subsequence](/content/questions/longest-common-subsequence/index.html)
Given two strings, return the longest common subsequence between the two strings.

### [Reverse Integer](/content/questions/reverse-integer/index.html)
Given a 32-bit signed integer, reverse digits of the integer.

### [Number of Islands](/content/questions/number-of-islands/index.html)
Given a 2D matrix, where "1" represents land and "0" represents water, count how many islands are present.

### [Boundary of Binary Tree](/content/questions/boundary-of-binary-tree/index.html)
The boundary of a binary tree is the concatenation of the root, the left boundary, the leaves ordered from left-to-right, and the reverse order of the right boundary.

### [Find the Missing Number in an Array](/content/questions/find-missing-number-in-array/index.html)
Given an unsorted array of unique integers (size n + 1) and a first array identical to the second array, missing one integer (size n), find and output the missing integer.
