✅ Array-Based Problems
1. Subarray with Given Sum
Problem:
Given an array of integers and a target sum k, return true if a contiguous subarray adds up
to k, otherwise return false.
Input: arr = [1, 4, 20, 3, 10, 5], k = 33
Output: true
Explanation: Subarray [20, 3, 10] adds to 33.
2. Find the First Missing Positive
Problem:
Given an unsorted array, find the smallest missing positive integer.
Input: [3, 4, -1, 1]
Output: 2
3. Majority Element (> n/2 times)
Problem:
Find the element that appears more than n/2 times in the array. If no such element exists,
return -1.
Input: [2, 2, 1, 1, 2, 2]
Output: 2
4. Product of Array Except Self
Problem:
Return an array such that each element is the product of all elements in the array except itself
(without using division).
Input: [1, 2, 3, 4]
Output: [24, 12, 8, 6]
5. Maximum Sum Subarray (Kadane's Algorithm)
Problem:
Find the contiguous subarray (containing at least one number) which has the largest sum and
return its sum.
Input: [-2,1,-3,4,-1,2,1,-5,4]
Output: 6
Explanation: [4,-1,2,1] has the largest sum = 6
✅ String-Based Problems
6. Longest Substring Without Repeating Characters
Problem:
Given a string, find the length of the longest substring without repeating characters.
Input: "abcabcbb"
Output: 3
Explanation: "abc" is the longest substring without duplicates.
7. Check for Anagram
Problem:
Write a function that checks if two strings are anagrams of each other.
Input: "listen", "silent"
Output: true
8. Longest Palindromic Substring
Problem:
Given a string, return the longest palindromic substring.
Input: "babad"
Output: "bab" or "aba"
9. Group Anagrams
Problem:
Given an array of strings, group the anagrams together.
Input: ["eat", "tea", "tan", "ate", "nat", "bat"]
Output: [["eat","tea","ate"], ["tan","nat"], ["bat"]]
10. String Compression
Problem:
Implement a method that performs basic string compression using counts of repeated
characters.
Input: "aabcccccaaa"
Output: "a2b1c5a3"