Additional Programming Question Set
Question 1: Top K Frequent Elements
Given an integer array nums and an integer k, return the k most frequent elements. You may return
the answer in any order.
Example:
Input: nums = [1,1,1,2,2,3], k = 2
Output: [1, 2]
Question 2: Product of Array Except Self
Given an array nums of n integers where n > 1, return an array output such that output[i] is equal to
the product of all the elements of nums except nums[i].
Example:
Input: nums = [1,2,3,4]
Output: [24,12,8,6]
Question 3: Letter Combinations of a Phone Number
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the
number could represent. (Use a standard phone keypad layout for the letters).
Example:
Input: digits = '23'
Output: ['ad','ae','af','bd','be','bf','cd','ce','cf']
Question 4: Longest Palindromic Substring
Given a string s, return the longest palindromic substring in s.
Example:
Input: s = 'babad'
Output: 'bab' or 'aba'
Question 5: Word Search
Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from
letters of sequentially adjacent cells, where 'adjacent' cells are horizontally or vertically neighboring.
Example:
Input: board = [['A','B','C','E'],['S','F','C','S'],['A','D','E','E']], word = 'ABCCED'
Output: true
Question 6: 3Sum
Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j != k,
nums[i] + nums[j] + nums[k] == 0.
Example:
Input: nums = [-1, 0, 1, 2, -1, -4]
Output: [[-1,-1,2],[-1,0,1]]
Question 7: Sliding Window Maximum
Given an array nums and a sliding window of size k, return the maximum values in each window.
Example:
Input: nums = [1,3,-1,-3,5,3,6,7], k = 3
Output: [3,3,5,5,6,7]
Question 8: Decode Ways
Given a string s containing only digits, return the number of ways to decode it (like encoding with
A=1, B=2, ..., Z=26).
Example:
Input: s = '226'
Output: 3 (decodes as 'BZ', 'VF', 'BBF')
Question 9: Count of Smaller Numbers After Self
You are given an integer array nums and need to return a new counts array. The count at each
index i represents the number of smaller elements to the right of i.
Example:
Input: nums = [5,2,6,1]
Output: [2,1,1,0]
Question 10: Median of Two Sorted Arrays
Given two sorted arrays nums1 and nums2 of size m and n, return the median of the two sorted
arrays.
Example:
Input: nums1 = [1,3], nums2 = [2]
Output: 2.0