110 data structures and algorithms questions110 Interview Questions
Convert a given string into a zigzag pattern with a specified number of rows. Then read the characters row by row to return the converted string.
#1. Zigzag Conversion
Design a data structure that acts as a Least Recently Used (LRU) cache. Implement methods to get and put key-value pairs, evicting the least recently used entry when the cache is full.
#2. LRU Cache
Determine if a given word can be constructed from letters in a 2D board, where letters can be used horizontally or vertically. Each letter can only be used once in the word.
#3. Word Search
You are given an array of strings. Determine how many strings within given ranges start and end with a vowel.
#4. Count Vowel Strings in Ranges
You are given an array of integers. Determine the minimum number of operations needed to sort the array in non-decreasing order, where each operation involves replacing an element with one or more elements that sum to the original value.
#5. Minimum Replacements to Sort the Array
Determine how many strings within a given array start and end with vowel letters, considering only a specified index range.
#6. Count the Number of Vowel Strings in Range
You are given a list of people's available time slots and a meeting duration. Find the earliest time slot that works for all participants to hold the meeting.
#7. Meeting Scheduler
You're given a list of words and a string of characters. Determine which words can be fully formed using only the characters from the given string, and return the sum of their lengths.
#8. Find Words That Can Be Formed by Characters
Given a grid representing land and water, count the number of distinct islands. An island is formed by connected land cells.
#9. Number of Islands
Determine the minimum time required to rearrange a binary string such that all 0s precede all 1s. Each second, adjacent '01' pairs can be swapped.
#10. Time Needed to Rearrange a Binary String
You are given a range of numbers and a set of banned numbers. Find the maximum number of integers you can choose from the range, excluding the banned ones.
#11. Maximum Number of Integers to Choose From a Range I
On a chessboard, you are given the starting positions of several chess pieces. Determine the number of valid combinations of moves for all pieces to reach their specified destinations, ensuring no two pieces occupy the same square at any point during the moves.
#12. Number of Valid Move Combinations On Chessboard
Find the maximum score of a subarray based on the frequency of its elements. The score is calculated using a specific formula involving the most frequent element's count.
#13. Maximum Frequency Score of a Subarray
Given an integer p, you can create an array of 2^p elements. The goal is to minimize the non-zero product of all elements in this array after performing specific modifications to its values.
#14. Minimum Non-Zero Product of the Array Elements
You're given a range of numbers and a set of banned numbers. Determine the maximum number of integers you can choose from the allowed range such that their sum doesn't exceed a given limit.
#15. Maximum Number of Integers to Choose From a Range II
You are given an array of numbers and a series of requests for ranges within the array. Find the permutation of the numbers that maximizes the total sum of the requested ranges.
#16. Maximum Sum Obtained of Any Permutation
Given an array of integers, determine how many pairs of numbers in the array have a product that is divisible by a given integer k. Count all such pairs and return the total.
#17. Count Array Pairs Divisible by K
Given a list of words, group together all the anagrams. Anagrams are words that contain the same letters rearranged.
#18. Group Anagrams
Imagine you're painting houses in a row, but with restrictions on color choices and neighborhood formations. Find the minimum cost to paint all houses while achieving a target number of neighborhoods.
#19. Paint House III
Given two digits, find the smallest multiple of a given integer that can be formed using only those two digits.
#20. Smallest Greater Multiple Made of Two Digits