Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

185 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🎯 Placement Preparation

Data Structures & Algorithms — C++ Solutions for Coding Interviews & Placement Drives

Language Problems Solved LeetCode GFG TCS NQT Infosys License

A hand-maintained archive of 165 solved problems in C++, built while grinding for coding interviews and company-specific placement tests — TCS NQT, Infosys, LeetCode, and GeeksforGeeks.

Problem ListStructureGetting StartedTopicsAuthor


📊 Repository Stats

🏢 Company / Platform 📁 Files 📈 Share
🟠 LeetCode 66 40%
🟢 GeeksforGeeks 52 32%
🔵 TCS / TCS NQT 21 13%
🟣 NQT (General) 6 4%
🟡 Infosys 3 2%
Miscellaneous DSA 17 10%
Total 165 100%

📌 About

This repository is a daily-practice log, not a curated tutorial — every file is a real problem attempted while preparing for placements. Problems are pulled from:

  • 🟠 LeetCode — classic interview questions across arrays, strings, DP, graphs, and heaps
  • 🟢 GeeksforGeeks — practice sets and daily Problem of the Day (POTD) challenges
  • 🔵 TCS NQT — questions and patterns from the TCS National Qualifier Test
  • 🟡 Infosys — questions based on Infosys placement test patterns
  • Miscellaneous — general DSA drills (Kadane's Algorithm, Stock Buy/Sell, Stickler Thief, etc.)

Many filenames are dated (tcs28june.cpp, nqt8jul.cpp, infosys17july.cpp) because they map to specific practice sessions — this repo effectively doubles as a prep timeline.

🧩 Solution Structure

Every file is self-contained and follows the same anatomy:

/*
   Problem statement, constraints, and example input/output
   copied in as a comment block for quick reference.
*/
#include <bits/stdc++.h>
using namespace std;

/* Core algorithm / solution function */
int solve(...) {
    // logic
}

/* Driver code - reads input from stdin, prints result to stdout */
int main() {
    // I/O handling
}

This means you can compile and run any single file in isolation to test it against sample input.

🚀 Getting Started

Prerequisites

  • A C++ compiler — g++ (GCC) recommended

Clone & Run

# 1. Clone the repository
git clone https://github.com/Coderamrish/Placement-Preparation.git
cd Placement-Preparation

# 2. Compile any solution
g++ -O2 -o solution leetcode215.cpp

# 3. Run it and provide input as described in the file's comment header
./solution

📋 Problem List

All 165 problems, grouped by company / platform. Click a section to expand.

🟠 LeetCode (66)
# File Problem
1 leetcode9.cpp Given an integer x, return true if x is a palindrome, and false otherwise.
2 leetcode20.cpp Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input str...
3 leetcode41.cpp Given an unsorted array of N integers, find the smallest missing
4 leetcode42.cpp Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how m...
5 leetcode55.cpp You are given an integer array nums. You are initially positioned at the array's first index, and each elem...
6 Leetcode136.cpp Given a non-empty array of integers nums, every element appears twice except for one. Find that single one.
7 leetcode162.cpp A peak element is an element that is strictly greater than its neighbors.
8 leetcode215.cpp Given an integer array nums and an integer k, return the kth largest element in the array.
9 leetcode231.cpp Given an integer n, return true if it is a power of two. Otherwise, return false.
10 leetcode242.cpp Given two strings s and t, return true if t is an anagram of s, and false otherwise.
11 leetcode268.cpp Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range...
12 leetcode365.cpp You are given two jugs with capacities x liters and y liters. You have an infinite water supply. Return whe...
13 leetcode371.cpp Given two integers a and b, return the sum of the two integers without using the operators + and -.
14 leetcode434.cpp Given two numbers, hour and minutes, return the smaller angle (in degrees) formed between the hour and the...
15 leetcode435.cpp There is a biker going on a road trip. The road trip consists of n + 1 points at different altitudes. The b...
16 leetcode440.cpp You are given three integers n, l, and r.
17 leetcode441.cpp You are given an integer array nums and an integer target.
18 leetcode443.cpp You are given an array of positive integers nums.
19 leetcode444.cpp You are given an array of positive integers arr. Perform some operations (possibly none) on arr so that it...
20 leetcode445.cpp Given an array of strings patterns and a string word, return the number of strings in patterns that exist a...
21 leetcode446.cpp Given a string s consisting only of characters a, b and c.
22 leetcode448.cpp You are given an m x n binary matrix grid and an integer health.
23 leetcode449.cpp You are given a directed acyclic graph of n nodes numbered from 0 to n − 1. This is represented by a 2D arr...
24 leetcode450.cpp You are given a positive integer n representing n cities numbered from 1 to n. You are also given a 2D arra...
25 leetcode451.cpp You are given a square board of characters. You can move on the board starting at the bottom right square m...
26 leetcode452.cpp Given an array intervals where intervals[i] = [li, ri] represent the interval [li, ri), remove all interval...
27 leetcode453.cpp You are given an integer n.
28 leetcode454.cpp You are given a string s of length m consisting of digits. You are also given a 2D integer array queries, w...
29 leetcode455.cpp You are given an integer n representing the number of nodes in a graph, labeled from 0 to n - 1.
30 leetcode456.cpp You are given an integer n representing the number of nodes in a graph, labeled from 0 to n - 1.
31 leetcode457.cpp You are given an undirected graph with N vertices numbered from 0 to N-1
32 leetcode458.cpp Given an array of integers arr, replace each element with its rank.
33 leetcode459.cpp A sequential digit number is a number in which every digit is exactly one greater than its previous digit.
34 leetcode460.cpp You are given an integer array nums.
35 leetcode461.cpp You are given an integer n. Your task is to compute the GCD (greatest common divisor) of two values:
36 leetcode462.cpp You are given an integer array nums of length n.
37 leetcode465.cpp Given a string s, return the lexicographically smallest subsequence of s that contains all the distinct cha...
38 leetcode466.cpp Given a 2D grid of size m x n and an integer k. You need to shift the grid k times.
39 leetcode467.cpp You are given a binary string s of length n, where:
40 leetcode468.cpp You are given a binary string s of length n, where:
41 leetcode470.cpp You are given an integer array nums.
42 leetcode471.cpp You are given a positive integer n.
43 leetcode502.cpp Suppose LeetCode will start its IPO soon. In order to sell a good price of its shares to Venture Capital, L...
44 leetcode628.cpp Given an integer array nums, find three numbers whose product is maximum and return the maximum product.
45 leetcode630.cpp There are n different online courses numbered from 1 to n. You are given an array courses where courses[i]...
46 leetcode1189.cpp Given a string text, you want to use the characters of text to form as many instances of the word "balloon"...
47 leetcode1383.cpp You are given two integers n and k and two integer arrays speed and efficiency both of length n. There are...
48 leetcode1394.cpp Given an array of integers arr, a lucky integer is an integer that has a frequency in the array equal to it...
49 leetcode1840.cpp You want to build n new buildings in a city. The new buildings will be built in a line and are labeled from...
50 leetcode2095.cpp You are given the head of a linked list. Delete the middle node, and return the head of the modified linked...
51 leetcode2161.cpp You are given a 0-indexed integer array nums and an integer pivot. Rearrange nums such that the following c...
52 leetcode2196.cpp You are given a 2D integer array descriptions where descriptions[i] = [parenti, childi, isLefti] indicates...
53 leetcode2754.cpp You are given a 0-indexed integer array nums of size n.
54 leetcode2812.cpp You are given a 0-indexed 2D matrix grid of size n x n, where (r, c) represents:
55 leetcode3312.cpp You are given an integer array nums of length n and an integer array queries.
56 leetcode3614.cpp You are given a string s consisting of lowercase English letters and the special characters: '*', '#', and...
57 leetcode3689.cpp You are given an integer array nums of length n and an integer k.
58 leetcode3691.cpp You are given an integer array nums of length n and an integer k.
59 leetcode3739.cpp You are given an integer array nums and an integer target.
60 Leetcode3753.cpp You are given two integers num1 and num2 representing an inclusive range [num1, num2].
61 leetocde464.cpp Given an integer array nums, return the greatest common divisor of the smallest number and largest number i...
62 leetocde973.cpp Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane and an integer k, r...
63 Leetocde3838.cpp You are given an array of strings words, where each string represents a word containing lowercase English l...
64 leetocde 2130.cpp Definition for singly-linked list
65 leetode439.cpp You are given three integers n, l, and r.
66 letcode1833.cpp It is a sweltering summer day, and a boy wants to buy some ice cream bars.
🟢 GeeksforGeeks (GFG) (52)
# File Problem
1 gfg353.cpp Given a matrix mat[][] of size n x m, where mat[i][j] represents the signal strength of a communication tow...
2 gfg423.cpp Given a singly linked list, remove all nodes that have a node with a greater value anywhere to their right...
3 gfg424.cpp Given an integer k representing the number of people to be seated and an array seats[], where 0 denotes an...
4 gfg425.cpp Given an array arr[] consisting of n distinct integers, find the maximum count of integers that are binary...
5 gfg426.cpp Given a string s of opening and closing brackets '(' and ')' only, find an equal point in the string. An eq...
6 gfg427.cpp Given a string s and an integer k, check if it is possible to convert s to a string that is repetition of a...
7 gfg428.cpp Given a number n, find count of all binary sequences of length 2n such that sum of first n bits is same as...
8 gfg429.cpp Given a matrix mat[][] of size n × m consisting of 0s and 1s. You start at the top-left cell (0, 0) and ini...
9 gfg431.cpp There is an array that initially contains only a single value, 0.
10 gfg432.cpp Given a rope of length n meters, cut it into multiple smaller ropes such that the product of their lengths...
11 gfg433.cpp Given a binary matrix mat[][] containing only 0s and 1s, find the total coverage of all 0's. The coverage o...
12 gfg434.cpp Given a sorted array arr[]. For each i(0 ≤ i ≤ n-1), make all the elements of the array from index 0 to i e...
13 gfg435.cpp Given two integers a and b in the form of strings. Return the last digit of ab.
14 gfg436.cpp Given a string s of lowercase English letters, you can swap all occurrences of any two distinct characters...
15 gfg437.cpp Given an integer array height[], where height[i] represents the height of the ith bar arranged in a row, fi...
16 gfg438.cpp There are infinitely many people standing in a row, indexed from 1. The strength of the person at index i i...
17 gfg439.cpp Given a matrix mat[][] of size n × n, where mat[i][j] represents the maximum number of steps a rat can jump...
18 gfg440.cpp Given an integer n, return all the n digit numbers in increasing order, such that their digits are in stric...
19 gfg441.cpp Given two strings, s1 and s2, count the number of subsequences of string s1 equal to string s2.
20 gfg442.cpp Given a floor of dimensions n × m and an unlimited supply of tiles of size 1 × m, find the total number of...
21 gfg443.cpp Given two integers n and k, count the number of binary strings of length n where adjacent 1 appear k times.
22 gfg444.cpp Given two arrays a[] and b[] of positive integers of size n and m respectively, where m ≤ n. You are allow...
23 gfg445.cpp Given two arrays a[] and b[] of size n and m respectively, find the minimum number of insertions and deleti...
24 gfg446.cpp Given an array arr[], find the maximum sum of a non-empty subarray. You are allowed to skip at most one ele...
25 gfg447.cpp Given an array arr[] of positive integers and a value k. Return true if the sum of any non-empty subset of...
26 gfg448.cpp Given two strings s1 and s2 consisting of lowercase English letters of length n1 and n2 respectively, find...
27 gfg449.cpp Given a binary string s consists only of 0s and 1s. Calculate the number of substrings that have more 1s th...
28 gfg450.cpp Given a string s consisting of lowercase English letters, find the maximum number of characters between any...
29 gfg451.cpp Given two sorted arrays of distinct integers in increasing order a[] and b[], which may have some common el...
30 gfg452.cpp Given two integers n and m, and an array arr[][] of size k, where arr[i] = [r, c] represents a blocked cell...
31 gfg454.cpp Given an array arr[] and positive integer k, count total number of pairs in the array whose sum is divisibl...
32 gfg455.cpp Given a number n, find the number of ways to represent this number as a sum of 2 or more consecutive natura...
33 gfg456.cpp Given a binary matrix of size M × N consisting of 0s and 1s,
34 gfg457.cpp Given an integer array arr[], where arr[i] denotes the number of tickets available with the i-th ticket sel...
35 gfg458.cpp Consider an array a[] = [1, 2, 3, ..., n] and a permutation b[] of size n containing all integers from 1 to...
36 gfg459.cpp See file for full problem statement
37 gfg460.cpp Given an array arr[] of size n containing positive integers, return the maximum length of the bitonic subar...
38 gfg461.cpp Given two integers n and sum, determine the number of n-digit positive integers whose digits add up to sum.
39 gfg462.cpp Given an array of integers arr[], find two non-overlapping contiguous sub-arrays such that the absolute dif...
40 gfg463.cpp Given a matrix of 0s and 1s and an integer k, divide the matrix into k pieces such that each piece has at l...
41 gfg464.cpp Given an array arr[] and a list of queries. For each query [l, r], find whether the subarray arr[l...r] is...
42 gfg465.cpp Given an array of strings arr[ ], find the shortest prefix of each string that uniquely identifies it among...
43 gfg466.cpp Given a string s containing lowercase English alphabets.
44 gfg467.cpp Given an array arr[], find the minimum number of elements to delete so that the remaining elements form a s...
45 gfg468.cpp Given an array arr[ ] consisting of distinct integers, check if the given array can represent preorder trav...
46 gfg469.cpp Given the root of a Binary Tree, find the length of the longest path consisting of connected nodes such tha...
47 gfg470.cpp Given a n × n grid mat[][] of integers where values can be negative, find the maximum sum among all possibl...
48 gfg571.cpp Given an integer array arr[] representing the nodes of a Complete Binary Tree in level order traversal, ret...
49 GfgPOTD420.cpp Given a string s consisting of n lowercase characters. Return the lexicographically smallest string after r...
50 gfgpotd421.cpp Given two integers n and m representing the dimensions of a chessboard, find the number of ways to place on...
51 gfgpotd422.cpp Consider a special family of Engineers and Doctors with following rules :
52 gfgpotd430.cpp Given a bag of size w kg and you are provided costs of packets different weights of oranges in array cost[]...
🔵 TCS / TCS NQT (21)
# File Problem
1 tcs6jul.cpp K-th Best selling Product Problem Description Amazon is preparing for its annual shopping
2 tcs6july.cpp Given a Time in 12-hour AM/PM format, convert it to 24 hour military time Note : 12:00 AM on a 12 -hour clo...
3 tcs8july.cpp Given a positive integer N, print all of its prime factors in increasing order.
4 tcs9jul.cpp Given a sorted array print all the indices of the given target element
5 tcs17june.cpp An array of size N contains from 0 to N - 1. Exactly one number is repeated and exactly one number is missing
6 tcs19.cpp you are given the values of the nodes of a binary search tree and an integer K
7 tcs21.cpp Given a square matrix of size N * N, calculate its trace.
8 tcs28.cpp Given an integer N, generate the first N terms of a series where:
9 tcs28ju.cpp There are N passengers who need to travel.
10 tcs28june.cpp Create a class that implements a Stack with following method
11 tcsbuysell.cpp Given an array prices where prices[i] is the price of a stock on day i, find the maximum profit achievable...
12 tcskadane's.cpp Given an array of N integers (which may include negative numbers), find and print the maximum sum obtainabl...
13 tcsmaxproduct.cpp Given an array of N integers (which may include negative numbers and zeros), find and print the largest pro...
14 tcsnqt6jul.cpp Given an integer N, print the first N fibonacci series.
15 tcsnqt8jul.cpp Given a sorted array of integers and a key, perform Binary Search.
16 tcsnqt16july.cpp You are given an array of integers of size $N$ and a target integer $T$. An "adjacent pair" is formed by an...
17 tcsnqt17june.cpp Two integres N and S are given.
18 tcsnqt19jul.cpp A historical department has developed a special roman numerical encoding system, in this system:
19 tcsnqt21.cpp Given two linked list, merge them by selecting elements alternatively from each list.
20 tcsnqt21july.cpp See file for full problem statement
21 tcsnqt28june.cpp There are two items A and B with their respective prices. write a program to determine which is more expensive
🟣 NQT (General Practice) (6)
# File Problem
1 nqt8jul.cpp Given the head of a singly linked list, sort the linked list using the Quick Sort algorithm.
2 nqt9jul.cpp Given an array return the first unique element using Hashmap
3 nqt19.cpp Given an array of integers, replace each element with its position (rank) in the sorted list of unique elem...
4 nqt21.cpp Write a program to perform the following operations on a stack.
5 nqt28ju.cpp Given an array heights[] where each element represents the height of a histogram bar and the width of every...
6 nqt28jun.cpp Given a string S, print the frequency of each distinct character in the order of its first occurrence.
🟡 Infosys (3)
# File Problem
1 infosys17july.cpp You are given a string S.
2 infosyspyq.cpp Andy wants to go on a vacation to de-stress himself. He can take only one continous vacation.
3 infosysq2.cpp There are N houses arranged in a straight line.Each house must be painted using one of C available
⚪ Miscellaneous DSA Practice (17)
# File Problem
1 cnt0's_and1s.cpp Maximum consecutive one’s (or zeros) in a binary array
2 cnt_distinct_subsequence.cpp Given a string str, Find the number of distinct subsequences that can be formed from it.
3 DecimaltoBinary.cpp Joseph is learning digital logic subject which will be for his next semester. He usually tries to solve uni...
4 idfc1.cpp Given two integers N (number of cakes) and M (number of people), determine the minimum number of cuts requi...
5 idfc2.cpp Smallest Concatenated Adjacent Number
6 last_student_score _freq.cpp You are thr student ID and corresponding score of N students.
7 maximum_element.cpp You are given an array of integers, arr,
8 minimum_jump_to_reach_end.cpp Given an array arr[] of non-negative integers, where each element represents the maximum number of steps yo...
9 move_zerostoEndTCS.cpp A chocolate factory is packing chocolates into the packets. The chocolate packets here represent an array o...
10 ques1.cpp Given an array Arr[] of N integers and a positive integer K, cyclically rotate the array clockwise by K.
11 ques2.cpp Given two non-negative integers n1 and n2, count how many numbers in the range [n1, n2] do not have repeate...
12 ques3.cpp Given a string, split it into exactly 3 palindromic substrings. If it's not possible, print "Impossible".
13 ques4.cpp Jack is always excited about sunday. It is favourite day, when he gets to play all day. And goes to cycling...
14 sticklerTheif.cpp Stickler Thief
15 stockbuy_and_sell.cpp Stock Buy and Sell - Max one Transaction Allowed
16 tcaap_gp.cpp Given the following inputs for an arithemetic Progression (AP):
17 top_k_frequent.cpp Given an array of match scores and an integer K, find the scores with the highest frequencies. print the sc...

🗂️ Topics Covered

Arrays Strings Two Pointers Sliding Window Hashing Sorting Binary Search Heaps / Priority Queues Dynamic Programming Greedy Graphs Trees Linked Lists Bit Manipulation Stacks & Queues Recursion & Backtracking Matrices

🎯 Purpose

  • ✅ Revise problem-solving patterns before interviews
  • ✅ Track daily/weekly DSA practice (dated files act as a timeline)
  • ✅ Build company-specific muscle memory for TCS NQT and Infosys test patterns
  • ✅ Maintain a searchable, personal archive of solved LeetCode & GFG problems

🤝 Contributing

This is primarily a personal prep log, but if you spot a bug, a more optimal approach, or want to suggest an improvement — issues and pull requests are welcome!

  1. Fork the repo
  2. Create a branch (git checkout -b improve/leetcode215)
  3. Commit your changes
  4. Open a pull request

📄 License

No license has been specified yet for this repository. All rights reserved by default unless stated otherwise by the author.

👤 Author

Coderamrish

GitHub

If this helped your placement prep, consider starring the repo!

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages