StringTCS NQT

Find the Index of First Occurrence in a String

Given two strings haystack and needle , find the index of the first occurrence of needle in haystack . If needle is not present in haystack , return -1 . tuf-examples-1 Input: haystack = "sadbutsad...

70.2k
Dynamic ProgrammingTCS NQT

Partition Equal Subset Sum

Problem Statement An array nums contains positive integers. Divide all array elements into two disjoint subsets so every element belongs to exactly one subset. Return true when both subsets can hav...

683
Dynamic ProgrammingTCS NQT

Minimum Coins

Problem Statement An array coins containing distinct positive coin denominations and a non-negative integer amount are given. Every denomination may be selected any number of times. Return the mini...

679
Dynamic ProgrammingTCS NQT

0/1 Knapsack

Problem Statement Two equal-length arrays weights and values describe available items. Entries at the same index form one item with a weight and a value. A non-negative integer capacity gives the m...

607
Dynamic ProgrammingTCS NQT

Longest Palindromic Subsequence

Problem Statement Given a string s , find the length of the longest palindromic subsequence. A subsequence may skip characters but must preserve the relative order of every selected character. Sele...

431
Dynamic ProgrammingTCS NQT

Longest Common Subsequence

Problem Statement Given two strings firstText and secondText , return the length of the longest character sequence appearing in both strings in the same relative order. A subsequence may delete zer...

495
JavaJavascriptSortingArraysC++PythonTCS NQT

Merge Two Sorted Arrays Without Extra Space

Problem Statement Given two sorted arrays nums1 of size m+n and nums2 of size n, where nums1 holds m valid elements followed by n zeros, merge nums2 into nums1 so the result is a single sorted arra...

1.6k
RecursionTCS NQT

Combination Sum

Problem Statement Given an array candidates containing distinct positive integers and an integer target , return all unique combinations with chosen numbers summing to target . The sa...

475
RecursionTCS NQT

Palindromic Partitioning

Input: s = "aab" Output: [["a", "a", "b"], ["aa", "b"]] Explanation: Both partitions cover the full string and every part is a palindrome. Input: s = "a" Output: [["a"]] Explanation: A single chara...

414
RecursionTCS NQT

Rat in a Maze

Problem Statement Given an n x n binary matrix maze , a rat starts at cell (0, 0) and must reach cell (n - 1, n - 1) . A cell with value 1 is open, and a cell with value 0 is blocked. Return all po...

352
SortingTCS NQT

Sort by Frequency

Input: arr = [5, 5, 4, 6, 4] Output: [4, 4, 5, 5, 6] Explanation: Values 4 and 5 appear 2 times each. Smaller value 4 comes before 5 , while value 6 comes last with frequency 1 . Input: arr = [3, -...

101.3k
StackTCS NQT

Sliding Window Maximum

Problem Statement An integer array nums and a positive integer k are given. A window containing exactly k consecutive elements starts at the left end of the array and moves right by one position at...

470