0% found this document useful (0 votes)
42 views5 pages

LeetCode Problems for Coding Interviews

The document outlines a series of programming problems categorized by difficulty levels: Easy, Medium, and Hard, with specific LeetCode references for each problem. It includes additional problems related to counting subarrays, string edit distance, and optimal time calculation, among others. Sample input and output formats are provided for some problems, along with constraints and examples.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views5 pages

LeetCode Problems for Coding Interviews

The document outlines a series of programming problems categorized by difficulty levels: Easy, Medium, and Hard, with specific LeetCode references for each problem. It includes additional problems related to counting subarrays, string edit distance, and optimal time calculation, among others. Sample input and output formats are provided for some problems, along with constraints and examples.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

More Questions:

Easy Level

Good warm-up and perfect for quick solutions under 10-15 minutes each.

 Two Sum (LeetCode #1)


→ Find indices of two numbers adding up to a target.

 Move Zeroes (LeetCode #283)


→ Shift all zeroes to end while maintaining order.

 Valid Parentheses (LeetCode #20)


→ Check if brackets are balanced.

 Count Frequency of Characters in String


→ Simple hash map usage.

 Maximum Subarray (LeetCode #53)


→ Kadane’s algorithm.

Medium Level

The sweet spot for HackWithInfy first round. Spend ~30-45 minutes per problem.

 Longest Substring Without Repeating Characters (LeetCode #3)


→ Sliding window technique.

 Subarray Sum Equals K (LeetCode #560)


→ Prefix sum + HashMap.

 Minimum Size Subarray Sum (LeetCode #209)


→ Sliding window.

 Group Anagrams (LeetCode #49)


→ Hashing sorted strings.

 Rotate Image (LeetCode #48)


→ Matrix manipulation.

 Find All Duplicates in an Array (LeetCode #442)


→ In-place marking.

 Coin Change (LeetCode #322)


→ Classic DP problem.

 Minimum Window Substring (LeetCode #76)


→ Advanced sliding window.

 Implement Trie (Prefix Tree) (LeetCode #208)

 Detect Cycle in Linked List (LeetCode #141)


 Find the Town Judge (LeetCode #997)
→ Graph degree problem.

Hard Level

Great prep for HackWithInfy Grand Finale or to ensure a top rank.

 Longest Increasing Subsequence (LeetCode #300)


→ DP with O(N log N) solution.

 Word Search II (LeetCode #212)


→ Backtracking + Trie.

 Number of Islands II (LeetCode #305)


→ Union-Find.

 Sliding Window Maximum (LeetCode #239)


→ Monotonic Queue.

 Palindrome Pairs (LeetCode #336)


→ String hashing or Trie.

 Minimum Cost to Connect All Points (LeetCode #1584)


→ Kruskal or Prim.

 Shortest Path in Binary Matrix (LeetCode #1091)

 Partition Equal Subset Sum (LeetCode #416)


→ DP subset sum.

Problem 1: Count Alternating Subarrays

Given an array of 0s and 1s, count the number of subarrays where no two adjacent elements are
the same.

Problem 2: String Edit Distance

Given two strings, find the minimum operations (insert, delete, replace) to convert one string
into another.

Problem 3: Optimal Time Calculation

A server processes tasks arriving at di erent times. Each task takes a fixed time to execute. Find
the total time taken to finish all tasks considering a cooldown period.
Problem 4: Product of Array Except Self

Given nums, return an array result where result[i] = product of all nums except nums[i], without
using division.

Problem 5: Minimum Jumps

You’re given an array where each element represents max jump length. Find minimum jumps to
reach end.

Focus on:

 Time and space complexity

 Edge cases

 Writing clean, readable code

Question 5:

There are three piles of stones. The first pile contains a stones, the second pile contains b
stones and the third pile contains c stones. You must choose one of the piles and split the
stones from it to the other two piles; specifically, if the chosen pile initially contained s stones,
you should choose an integer k (0≤k≤s), move k stones from the chosen pile onto one of the
remaining two piles and s−k stones onto the other remaining pile. Determine if it is possible for
the two remaining piles (in any order) to contain x stones and y stones respectively after
performing this action.

INPUT FORMAT :

 The first line of the input contains a single integer T denoting the number of test cases.
The description of T test cases follows.

 The first and only line of each test case contains five space-separated integers

a,b,c, x and y.

OUTPUT FORMAT :

For each test case, print a single line containing the string “YES” if it is possible to obtain piles of
the given sizes or “NO” if it is impossible.

CONSTRAINTS :

 1 <= T <= 100

 1 <= a,b,c,x,y <= 10^9

SAMPLE INPUT :

12324
32565

24262

6 5 2 12 1

SAMPLE OUTPUT :

YES

NO

YES

NO

Test case 1: You can take the two stones on the second pile, put one of them on the first pile
and the other one on the third pile.

Test case 2: You do not have enough stones.

Test case 3: You can choose the first pile and put all stones from it on the second pile.

Question 6:

Altaf has recently learned about number bases and is becoming fascinated.

Altaf learned that for bases greater than ten, new digit symbols need to be introduced, and that
the convention is to use the first few letters of the English alphabet. For example, in base 16, the
digits are 0123456789ABCDEF. Altaf thought that this is unsustainable; the English alphabet
only has 26 letters, so this scheme can only work up to base 36. But this is no problem for Altaf,
because Altaf is very creative and can just invent new digit symbols when she needs them. (Altaf
is very creative.)

Altaf also noticed that in base two, all positive integers start with the digit 1! However, this is the
only base where this is true. So naturally, Altaf wonders: Given some integer N, how many bases
b are there such that the base-b representation of N starts with a 1?

INPUT FORMAT :

The first line of the input contains an integer T denoting the number of test cases. The
description of T test cases follows.

Each test case consists of one line containing a single integer N (in base ten).

OUTPUT FORMAT :

For each test case, output a single line containing the number of bases b, or INFINITY if there
are an infinite number of them.

CONSTRAINTS :
 1 <= T <= 10^5

 0 <= N < 10^12

SAMPLE INPUT :

11

24

SAMPLE OUTPUT :

14

Common questions

Powered by AI

The solution to involve the combination of backtracking to explore paths on the grid and implementing a Trie data structure to efficiently check for the presence of words, cutting down on the search space .

To determine if it's possible to redistribute stones to match the target sizes, calculate the total number of stones, total = a + b + c. Check if the sum of x and y is equal to total and whether max(x, y) is less than or equal to total - max(a, b, c). This accounts for moving stones without exceeding the count in a single pile .

Matrix manipulation for image rotations typically involves transposing the matrix and then reversing each row. This mimics a 90-degree rotation to obtain the desired orientation in linear time complexity .

The sliding window technique involves adjusting the range of usefulness of data by expanding or contracting a 'window' across the dataset. It's used in the 'Longest Substring Without Repeating Characters' problem to track the indices or count of characters to ensure no repeats within the current window .

Optimize task execution by scheduling tasks such that the cooldown time is utilized effectively, using priority queues or similar structures to hold tasks. Track task completion times and dynamically adjust the order for minimal idle time .

A helpful heuristic might be to choose the pile with the stones that would exceed a target size. Then, distribute them such that the redistribution balances or matches the sizes required by the other two piles. This enables the largest flexibility in adjustment .

To solve the product of array except self without division, create two arrays representing cumulative product from left to right and right to left. Then multiply corresponding entries from these arrays for the result .

A BFS approach using a queue can efficiently explore all possible paths in a level-wise manner. It systematically checks each matrix cell's adjacency and updates the shortest path count when the endpoint is reached .

Kadane's algorithm efficiently finds the maximum sum of a contiguous subarray by maintaining a running tally of maximum sums up to each point, resetting when it becomes negative, which avoids recalculating sums from scratch .

Prefix sums and hash maps can be used to track cumulative sums as you iterate through the array. By storing the number of times each prefix sum has occurred, you can determine if there’s a subarray sum equal to the target by checking the difference between the current prefix sum and the target in the map .

You might also like