This repository contains a few beginner-friendly LeetCode problems. These questions help build confidence with arrays, loops, and basic logic. Each problem is simple, clear, and great for improving problem-solving skills step-by-step.
-
For each kid, check if giving them extra candies makes them have the most candies.
-
Helps understand comparing values in an array.
-
Returns a list of true/false based on who can reach the maximum.
-
Calculates the running total of numbers from left to right.
-
Helps practice loops and keeping track of a growing sum.
-
Great for understanding how prefix sums work.
-
Mixes two halves of an array into an alternating pattern.
-
Builds understanding of index handling and rearranging lists.
-
Very useful for practicing basic array manipulation.
-
You are given an array of integers called nums.
-
You need to look at two different positions in the array at a time.
-
For each pair of positions (i, j), check that i < j.
-
Compare the values at those positions: nums[i] and nums[j].
-
If both values are equal, then that pair is called a good pair.
-
Count all such good pairs and return the total count.
-
You are given a list (array) of integers.
-
Take one number at a time from the list.
-
Count how many digits that number contains.
-
Check whether the digit count is an even number.
-
Keep a running count of all numbers that have an even number of digits.
-
After checking all the numbers, return the final count.
-
You are given a list of integers.
-
Pick one number and compare it with the numbers that come after it in the list.
-
For each comparison, check whether both numbers are equal.
-
Make sure the index of the first number is smaller than the index of the second number.
-
If both conditions are satisfied, consider it a valid (good) pair.
-
Count all such valid pairs and return the total count.
-
You are given a list of integers.
-
Pick one number from the list.
-
Compare this number with all other numbers in the list.
-
Count how many numbers are smaller than the current number.
-
Store this count in the result list at the same position.
-
Repeat the process for every number and return the final list of counts.
-
You are given a single integer number.
-
Break the number into its individual digits.
-
Calculate the product of all the digits.
-
Calculate the sum of all the digits.
-
Subtract the sum of the digits from the product of the digits.
-
Return the final result.
-
You are given two integers: n and start.
-
Create an array with length n.
-
For each index i, calculate the value using the formula start + 2 × i.
-
Store each calculated value in the array.
-
Apply the XOR operation between all the elements of the array.
-
Return the final XOR result.
- Difficulty: Easy
- Given an integer array nums, choose two different indices i and j and return the maximum value of (nums[i]−1)∗(nums[j]−1)
-
Identify the two largest elements in the array
-
Subtract 1 from each
-
Compute the product
-
Greedy selection
-
Array scanning
-
Optimization without sorting
- Difficulty: Medium
-
Given unique soldier ratings, count the number of valid teams of size 3 such that:
-
Ratings are strictly increasing or
-
Ratings are strictly decreasing with indices i < j < k.
-
Fix a middle soldier
-
Count smaller and larger elements on both sides
-
Combine counts to form valid triplets
-
Nested iteration with constraints
-
Combinatorial counting
-
Pattern recognition (increasing vs decreasing sequences)
- Difficulty: Easy
- Given startTime, endTime, and queryTime, return how many students are doing homework at queryTime.
-
Iterate through students
-
Check if queryTime lies in the inclusive interval
-
Interval validation
-
Linear scanning
-
Condition-based counting
- Difficulty: Easy
-
Reduce a number to zero using:
-
Divide by 2 if even
-
Subtract 1 if odd
-
Return the number of steps.
-
Repeatedly apply rules until the number becomes zero
-
Maintain a step counter
-
Loop control
-
Even/odd logic
-
Simulation-based problem solving
- Difficulty: Easy
- For a given integer n, return an array where each index i contains the count of 1s in the binary representation of i.
-
Build results incrementally from 0 to n
-
Leverage previous computations (dynamic programming)
-
Bit manipulation
-
Dynamic programming mindset
-
Binary number understanding
-
Language: Python
-
Paradigm: Iterative, Greedy, Dynamic Programming
-
Time: O(n), O(n²) where required
-
Space: Optimized, minimal auxiliary usage
-
Pick any problem from the list.
-
Read the short explanation.
-
Check or write your solution inside the solutions/ folder.