Daily Coding Challenges
Practice DSA problems, sharpen your skills. Click ✅ to mark as solved.
Two Sum
Given an array of integers `nums` and an integer `target`, return indices of the two numbers that add up to `target`. You may assume each input has exactly one solution.
Input: nums = [2, 7, 11, 15], target = 9 Output: [0, 1] Explanation: Because nums[0] + nums[1] == 9
Reverse a String
Write a function that reverses a string in-place. The input is an array of characters `s`.
Input: s = ["h","e","l","l","o"] Output: ["o","l","l","e","h"]
Valid Parentheses
Given a string `s` containing '(', ')', '{', '}', '[', ']', determine if the input string is valid. An input string is valid if brackets are closed in the correct order.
Input: s = "()[]{}" → Output: true
Input: s = "(]" → Output: falseFibonacci Number
Given `n`, calculate F(n) of the Fibonacci sequence where F(0)=0 and F(1)=1. F(n) = F(n-1) + F(n-2) for n > 1.
Input: n = 4 → Output: 3 Explanation: F(4) = F(3) + F(2) = 2 + 1 = 3
Maximum Subarray
Given an integer array `nums`, find the contiguous subarray (at least one element) which has the largest sum and return its sum.
Input: nums = [-2,1,-3,4,-1,2,1,-5,4] Output: 6 Explanation: [4,-1,2,1] has the largest sum = 6
Climbing Stairs
You are climbing a staircase. It takes `n` steps to reach the top. Each time you can climb 1 or 2 steps. How many distinct ways can you climb to the top?
Input: n = 3 → Output: 3 Explanation: 1+1+1, 1+2, 2+1
Binary Search
Given a sorted array of integers `nums` and an integer `target`, write a function to search `target` in `nums`. Return the index if found, else return -1.
Input: nums = [-1,0,3,5,9,12], target = 9 → Output: 4 Input: nums = [-1,0,3,5,9,12], target = 2 → Output: -1
Merge Intervals
Given an array of `intervals` where intervals[i] = [starti, endi], merge all overlapping intervals and return an array of all non-overlapping intervals.
Input: [[1,3],[2,6],[8,10],[15,18]] Output: [[1,6],[8,10],[15,18]]
LRU Cache
Design a data structure that follows Least Recently Used (LRU) cache constraints. Implement `get(key)` and `put(key, value)` both in O(1) time.
LRUCache(2)
put(1, 1) → cache: {1=1}
put(2, 2) → cache: {1=1, 2=2}
get(1) → 1 (cache: {2=2, 1=1})
put(3, 3) → evicts 2, cache: {1=1, 3=3}Word Search
Given an `m x n` grid of characters and a string `word`, return true if `word` exists in the grid. The word must be formed from letters of sequentially adjacent cells (horizontally or vertically).
Grid: [["A","B","C"],["S","F","C"],["A","D","E"]] word = "ABCCED" → true