Algorithms Flashcards
Contains duplicates
Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.
Two sum
Given an array of numbers [1, 2, 3, 4] and target int 7. Goal is to return indexes of two numbers from the array so the sum of these two would be 7.
Valid anagram
Given two strings ‘racecar’, ‘raceacr’. Return if these two words are annagrams.
Anagram groups
Given an array of strings (etc [“cat”, “hat,” “atc”]). The goal is to group them. For example in the case above it will be [[“cat”, “atc”], [“hat”]]
Top K Frequent Elements
Given an integer array nums and an integer k, return the k most frequent elements within the array. For example: nums = [1,2,2,3,3,3], k = 2 and return [2,3]
Validate Parentheses
You are given a string s consisting of the following characters: ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’.
Min stack
The goal is to build minimal stack functionality with one additional extra feature. This extra feature is returning minimal value in the stack.
Valid palindrome
Given a string s, return true if it is a palindrome, otherwise return false.
Merge sorted array
You are given two sorted arrays ([1, 2, 3, 0, 0] and [2,5]). The goal is to merge them into one (into the first), sure the new array must be sorted.
Remove duplicates from sorted array
You are given two sorted arrays ([1, 2, 3, 0, 0] and [2,5]). The goal is to merge them into one (into the first), sure the new array must be sorted.
Move zeroes
Given an integer array nums, move all 0’s to the end of it while maintaining the relative order of the non-zero elements.
Note that you must do this in-place without making a copy of the array.
Reverse a string
Write a function that reverses a string. The input string is given as an array of characters s.
You must do this by modifying the input array in-place with O(1) extra memory.
Squares of sorted array
Given an integer arraynumssorted innon-decreasingorder, returnan array ofthe squares of each numbersorted in non-decreasing order.
Two Sum II (input array is sorted)
Given an array of integers numbers that is sorted in non-decreasing order.
Return the indices (1-indexed) of two numbers, [index1, index2], such that they add up to a given target number target and index1 < index2. Note that index1 and index2 cannot be equal, therefore you may not use the same element twice.
Invert binary tree
You are given the root of a binary treeroot
. Invert the binary tree and return its root.