0% found this document useful (0 votes)
41 views

Cheatspeet Dsa

Uploaded by

negianuj070
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Cheatspeet Dsa

Uploaded by

negianuj070
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
You are on page 1/ 114

1 Day1 Control Structure

2 Day1 Control Structure

3 Day1 Control Structure


4 Day1 Control Structure

5 Day1 Control Structure

6 Day1 Control Structure

7 Day1 Control Structure

8 Day1 Control Structure

9 Day1 Control Structure


10 Day1 Control Structure

11 Day1 Control Structure

12 Day1 Control Structure


13 Day1 Control Structure

14 Day1 Control Structure


1 Day2 Loop & Pattern

2 Day2 Loop & Pattern

3 Day2 Loop & Pattern

4 Day2 Loop & Pattern


5 Day2 Loop & Pattern
6 Day2 Loop & Pattern

7 Day2 Loop & Pattern

8 Day2 Loop & Pattern

9 Day2 Loop & Pattern

10 Day2 Loop & Pattern

11 Day2 Loop & Pattern


12 Day2 Loop & Pattern

13 Day2 Loop & Pattern

14 Day2 Loop & Pattern

15 Day2 Loop & Pattern


16 Day2 Loop & Pattern

17 Day2 Loop & Pattern

18 Day2 Loop & Pattern

19 Day2 Loop & Pattern


1 Day3 Function

2 Day3 Function

3 Day3 Function
4 Day3 Function

5 Day3 Function
6 Day3 Function

7 Day3 Function

8 Day3 Function

9 Day3 Function
10 Day3 Function

11 Day3 Function

12 Day3 Function

13 Day3 Function
14 Day3 Function

15 Day3 Function
16 Day3 Function

17 Day3 Function

1 Day4 Array & Strings


2 Day4 Array & Strings
3 Day4 Array & Strings
4 Day4 Array & Strings
5 Day4 Array & Strings
6 Day4 Array & Strings
7 Day4 Array & Strings
8 Day4 Array & Strings
9 Day4 Array & Strings
10 Day4 Array & Strings

11 Day4 Array & Strings


12 Day4 Array & Strings

13 Day4 Array & Strings

14 Day4 Array & Strings

15 Day4 Array & Strings

16 Day4 Array & Strings


17 Day4 Array & Strings

18 Day4 Array & Strings

19 Day4 Array & Strings

20 Day4 Array & Strings

21 Day4 Array & Strings

22 Day4 Array & Strings


23 Day4 Array & Strings

1 Day5 Structure
2 Day5 Structure

3 Day5 Structure
4 Day5 Structure

5 Day5 Structure
6 Day5 Structure

7 Day5 Structure
8 Day5 Structure

9 Day5 Structure
10 Day5 Structure
11 Day5 Structure
12 Day5 Structure
13 Day5 Structure

1 Day 6 Mathematics

2 Day 6 Mathematics
3 Day 6 Mathematics

4 Day 6 Mathematics
5 Day 6 Mathematics

6 Day 6 Mathematics
7 Day 6 Mathematics
8 Day 6 Mathematics

9 Day 6 Mathematics
10 Day 6 Mathematics

11 Day 6 Mathematics

12 Day 6 Mathematics

13 Day 6 Mathematics

14 Day 6 Mathematics

15 Day 6 Mathematics
16 Day 6 Mathematics

17 Day 6 Mathematics
Find N-th term in the
1 Day 7 series

2 Day 7 Minimum Height Triangle

3 Day 7 Maximum Draws

4 Day 7 Handshake

Number of Steps to
5 Day 7 Reduce a Number to Zero
6 Day 7 Self Dividing Numbers

7 Day 7 Divisor Game

8 Day 7 Factorial Trailing Zeroes

9 Day 7 Perfect Number

10 Day 7 Count Primes

1 Day 8 Army Game


2 Day 8 Connecting Towns

3 Day 8 Cutting Paper Squares

4 Day 8 Best Divisor

5 Day 8 Restaurant

6 Day 8 Reverse Game

7 Day 8 Straight grid Again


8 Day 8 Halloween party

9 Day 8 Filling Jars

Sumar and the Floating


1 Day 9 Rocks

2 Day 9 Constructing a Number

3 Day 9 Sherlock and GCD

4 Day 9 Identify Smith Numbers


5 Day 9 John and GCD list

6 Day 9 Picking Cards

7 Day 9 Combo Meal

8 Day 9 Number Groups

9 Day 9 Points On a Line


10 Day 9 Most Distant

1 Day 10 Alternate Elements

2 Day 10 Mini Max Sum

3 Day 10 Ishaan loves chocolates

4 Day 10 Fighting the darkness


5 Day 10 Left and Right

6 Day 10 absolute difference

7 Day 10 tough competitors

first and last occurrence of


8 Day 10 x

9 Day 10 Two Sum


10 Day 10 last duplicate element

1 Day 11 Equalize the Array

2 Day 11 shuffle the array

3 Day 11 Left Element

4 Day 11 Perfect Array


5 Day 11 Left Rotation

6 Day 11 Replace elements

7 Day 11 Rotate array

8 Day 11 Longest subarray

9 Day 11 Sort the array


10 Day 11 Even number of digits

1 Day 12 Minimum Time

2 Day 12 Common Characters

3 Day 12 Average salary


4 Day 12 Capacity to ship

5 Day 12 Least unique elements

6 Day 12 Corporate flight booking

7 Day 12 Find minimum

8 Day 12 Duplicate number


9 Day 12 Average Waiting Time

10 Day 12 Maximum units

1 Day 13 Summing the N series

2 Day 13 Diwali Lights


3 Day 13 Die Hard 3

4 Day 13 Is Fibo

5 Day 13 K Candy Store

6 Day 13 Bus Station


7 Day 13 Jim and the Jokes

8 Day 13 Strange Grid Again

1 Day 13 Closest Number

2 Day 13 Primitive Problem


3 Day 14 Equations

4 Day 14 Binomial Coefficients

5 Day 14 Lucy and Flowers

6 Day 14 Divisibility of Power


7 Day 14 A Weird Function

8 Day 14 Coprime Conundrum

1 Day 15 Ants

2 Day 15 Ichigo and Cubes


3 Day 15 Salary Blues

4 Day 15 Breaking Sticks

Number of zero-xor
5 Day 15 subsets

6 Day 15 Manasa loves Maths


7 Day 15 Easy math

8 Day 15 Mutual Recurrences


Write a program that takes a character as input and prints either 1, 0 or -1 according to the following rules.
1, if the character is an uppercase alphabet (A - Z)
0, if the character is a lowercase alphabet (a - z)
-1, if the character is not an alphabet

Write a program to calculate the total salary of a person. The user has to enter the basic salary (an integer) and the grade (an

totalSalary = basic + hra + da + allow – pf


where :
hra = 20% of basic
da = 50% of basic
allow = 1700 if grade = ‘A’
allow = 1500 if grade = ‘B’
allow = 1300 if grade = ‘C' or any other character
pf = 11% of basic.
Round off the total salary and then print the integral part only.

check whether a number entered by the user is even or odd.


find the ASCII value of a character.

find the largest number among the three numbers entered by the user.

check whether an alphabet entered by the user is a vowel or a consonant.

check whether the year entered by the user is a leap year or not.

check if two given non-negative integers have the same last digit.
Write a program in C to read any day number in integer and display day name in the word

Write a C program to check whether a triangle is Equilateral, Isosceles or Scalene.

Write a program in C to read any Month Number in integer and display the number of days for this month
Write a C program to read temperature in centigrade and display a suitable message according to temperature state below : G
Temp < 0 then Freezing weather
Temp 0-10 then Very Cold weather
Temp 10-20 then Cold weather
Temp 20-30 then Normal in Temp
Temp 30-40 then Its Hot
Temp >=40 then Its Very Hot

Write a C program to accept a coordinate point in a XY coordinate system and determine in which quadrant the coordinate po
Given a number N, print sum of all even numbers from 1 to N.

Given three values - Start Fahrenheit Value (S), End Fahrenheit value (E) and Step Size (W), you need to convert all Fahrenheit
the table.

1
23
345
4567

Pattern for N = 4
1
23
345
4567
Write a program to input an integer N and print the sum of all its even digits and sum of all its odd digits separately.
Digits mean numbers, not the places! That is, if the given integer is "13245", even digits are 2 & 4 and odd digits are 1, 3 & 5.
Write a program to find x to the power n (i.e. x^n). Take x and n from the user. You need to print the answer.
Note : For this question, you can assume that 0 raised to the power of 0 is 1
A
BB
CCC

A
BC
CDE
DEFG

E
DE
CDE
BCDE
ABCDE

1
232
34543
4567654 Pattern for N = 4

Pattern for N = 4
1
212
32123
4321234
Findiing the Factorial of the given number

Take input a stream of n integer elements, find the second largest element present.
The given elements can contain duplicate elements as well. If only 0 or 1 element is given, the second largest should be INT_M

*
***
*****
*******

*
***
*****
***
*
*
***
*****
*****
***
*

*****
***
*
***
*****

11
12 21
123 321
1234 4321
1234554321

1234554321
1234 4321 123 321 12 21 1 1
Fibonacci Series is defined by the recurrence
F(n) = F(n-1) + F(n-2)

Write a program to swap two numbers using function.

Write a program to find mean and median of five numbers using function
Find the sum of first n terms of the following series:
a) 1 + 2! + 3! + 4!...................
b) 1+ x + x2/2! + x3/3! + x4/4!......
c) 1- x + x2/2! - x3/3! + x4/4!......
d) x- x3/3! + x5/5! - x7/7!........
e) 1- x2/2! + x4/4! - x6/6!........

Program to find power of a number using function


Print first n members of fibonacii series
Fibonacci Series is defined as
F(n) = F(n-1) + F(n-2)
where F(0) = 0 and F(1) = 1
Write a program to swap two numbers using function.

Write a program to find the sum of the series using the function. a) 1!/1+2!/2+3!/3+4!/4+5!/5

Write a program to print all perfect numbers in given range using the function.
Display Prime Numbers Between Intervals Using Function

Write a program to find diameter, circumference and area of circle using functions. Also find the area and volume of a given co

Program to find power of a number using function.

Program to find reverse of a number using function


Program to find sum of even or odd number in given range using recursion

write a function int max_of_four(int a, int b, int c, int d) which reads four arguments
and returns the greatest of them..

Input will contain four integers - a,b,c,d, one in each line.

Output Format

Print the greatest of the four integers.


Note: I/O will be automatically handled.
Write a program to find mean and median of five numbers using function

Print first n members of fibonacii series


Fibonacci Series is defined as
F(n) = F(n-1) + F(n-2)
where F(0) = 0 and F(1) = 1

Print alternate elements of an array: You are given an array A of size N. You need to print elements of A in alternate order (sta
Ishaan Loves Chocolates: As we know, Ishaan has a love for chocolates. He has bought a huge chocolate bar that contains N ch
Ishaan can eat the first or the last square of the chocolate at once. Ishaan has a sister who loves chocolates too and she dema
Determine the tastiness level of the square which his sister gets.
Input: First line contains N, Number of chocolate squares and 2nd line contains space separated N elements as the sweetness
Output: 0ne number representing sweetness of the square received by ishan’s sister
Fighting the darkness: Given an array arr[] of size N representing the size of candles which reduce by 1 unit each day. The room
without darkness.
Input: First line contains N, Number of candles and 2nd line contains space separated N elements as height of all candles as ar
Output: Number of days the room can be illuminated.
Multiply left and right array sum: Pitsy needs help in the given task by her teacher. The task is to divide a array into two sub ar
multiply both the subarrays.

Input: First line contains N, Number of elements and 2nd line contains space separated N elements of array A.
Output: A number resulting multiplication of sum of left half elements to right half elements.
Absolute Difference of 1: Given an array arr of size n. Print all the numbers less than k and should be such that the difference b
Note: Return empty list if no such number present, driver code will automatically print -1.
Input: First line contains two space separated numbers N and K, Number of elements in array and value of K and 2nd line cont
Output: Space separated numbers which satisfy the given condition.
Tough Competitors: There are n competitors in an exam. Each competitor has his own skill value which is given by the array ar
on. Two competitors are said to be tough competitors if their skill difference is least i.e. they are very close in their skill values
and print the absolute of the difference of their skill values.
Input: First line contains N, Number of competitors and 2nd line contains space separated N elements as the skill value of all c
Output: The absolute difference of skill values of tough competitors.
You have been given a random integer array/list(ARR) and a number X. Find and return the number of triplets in the array/list
You have been given an empty array(ARR) and its size N. The only input taken from the user will be N and you need not worry
Your task is to populate the array using the integer values in the range 1 to N(both inclusive) in the order - 1,3,.......4,2.
You have been given an array/list(ARR) of size N. You need to swap every pair of alternate elements in the array/list.
You don't need to print or return anything, just change in the input array itself.
You have been given an integer array/list(ARR) of size N. Where N is equal to [2M + 1].
Now, in the given array/list, 'M' numbers are present twice and one number is present only once.
You need to find and return that number which is unique in the array/list.

Reverse the elements of an Array. That is, first element should become last and last should come at first place.
Given an Array of N elements, find their Mean and Median values

Program for finding length of a string

Program for reversing the given string

Program for finding if the given string is a palindrome

Program for finding word count in the Paragraph


Program for converting all lower case letters to upper case and vice versa in the given sentence

Program for comparing two strings

Program for concatenation of two strings

Program for finding all prefixes of a string

Program for finding all suffixes of a string

Program for character by character frequency count


Program to remove whitespace from the beginning, end, or both beginning and end, of a string

Get the input of student: Name, Roll No, Marks in 6 subjects in 12th. Find if the student is eligible for admission in Delhi Unive
Write a program to store and print the roll no., name, age and marks of a student using structures. Write a program
details of the student with roll no. 1.

3. Write a program to store and print the roll no., name, age, address and marks of 15 students using structure.
4. Write a program to add two distances in inch-feet using structure. The values of the distances is to be taken from

5. Write a program to add two complex numbers using structure. The values of the complex number is to be taken fr
6. Write a program to add two time in hour, minute and second using structure. The values of the time is to be taken

7. Enter the marks of 5 students in Chemistry, Mathematics and Physics (each out of 100) using a structure named
and then display the percentage of each student.
8. Write a program to add, subtract and multiply two complex numbers using structures to function.

9. Write a structure to store the roll no., name, age (between 11 to 14) and address of students (more than 10). Stor
students having age 14.
- Write another function to print the names of all the students having even roll no.
- Write another function to display the details of the student whose roll no is given (i.e. roll no. entered by the user).
10. Write a structure to store the name, account number and balance of customers (more than 10) and store their in
balance less than $200.
2 - Write a function to add $100 in the balance of all the customers having more than $1000 in their balance and the
11. Write a program to compare two dates entered by user. Make a structure named Date to store the elements day
equal" otherwise display "Dates are not equal".
12. Write a structure to store the names, salary and hours of work per day of 10 employees in a company. Write a p
follows and then print the name of all the employees along with their final salaries. Hours of work per day 8
Increase in salary $50
13. Let us work on the menu of a library. Create a structure containing book information like accession number, nam
menu in which the following can be done.
1 - Display book information
2 - Add a new book
3 - Display all the books in the library of a particular author
4 - Display the number of books of a particular title
5 - Display the total number of books in the library
6 - Issue a book
(If we issue a book, then its number gets decreased by 1 and if we add a book, its number gets increased by 1)

find the roots of a quadratic equation

Given two numbers A and B. The task is to find out their GCD.
Given two numbers A and B, find Kth digit from right of A to the power B.

Given a number N, check if a number is perfect or not. A number is said to be perfect if sum of all its factors excluding the num

Note:- 6, 28, 496, and 8,128 are perfect number


Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.

For example, if we conisder 98, we get 9+8 = 17 after first addition. Then we get 1+7 = 8. We stop at this point because we are

Given two numbers A and B which define a range, where A < B. Find the count of total numbers in the given range [A … B] divi
Given an odd-digit-number N, you need to find whether the given number is a balanced-number or not. An odd digit number i
sum of all digits to the right of the middle digit is equal.

Note:- The number of digits of 1234006. is 7, i.e. odd digits. The middle digit is 4. LHS sum is 1+2+3=6, and RHS sum is 0+0+6=6
Given a number N, print least prime factors for all numbers from 1 to N.

The least prime factor of an integer N is the smallest prime number that divides it. The least prime factor of all even numbers
Note : 1 needs to be printed for 1.

Input: N = 6
Output: 1 2 3 2 5 2
Constraints: 2 ≤ N ≤ 1000

Given two numbers A and B. The task is to find out their LCM
Given radius of a circle, find the area of largest possible rectangle which may be enclosed completely within it.

Given a positive integer n and the task is to find the sum of series
1*2*3 + 2*3*4 +3*4*5+ 4*5*6 + . …... .+ n*(n+1)*(n+2).

1 + 2! + 3! + 4!...................

1+ x + x2/2! + x3/3! + x4/4!......

1- x + x2/2! - x3/3! + x4/4!......

x- x3/3! + x5/5! - x7/7!........


1- x2/2! + x4/4! - x6/6!........

Print all prime factors of the given number


https://practice.geeksforgeeks.org/problems/find-n-th-term-in-the-series3926/1/?category[]=Mathematical&category[]=Mat

https://www.hackerrank.com/challenges/lowest-triangle/problem

https://www.hackerrank.com/challenges/maximum-draws/problem

https://www.hackerrank.com/challenges/handshake/problem

https://leetcode.com/problems/number-of-steps-to-reduce-a-number-to-zero/
https://leetcode.com/problems/self-dividing-numbers/

https://leetcode.com/problems/divisor-game/

https://leetcode.com/problems/factorial-trailing-zeroes/

https://leetcode.com/problems/perfect-number/

https://leetcode.com/problems/count-primes/

https://www.hackerrank.com/challenges/game-with-cells/problem
https://www.hackerrank.com/challenges/connecting-towns/problem

https://www.hackerrank.com/challenges/p1-paper-cutting/problem

https://www.hackerrank.com/challenges/best-divisor/problem

https://www.hackerrank.com/challenges/restaurant/problem

https://www.hackerrank.com/challenges/reverse-game/problem

Strange Grid Again | HackerRank


Halloween party | HackerRank

Filling Jars | HackerRank

https://www.hackerrank.com/challenges/harry-potter-and-the-floating-rocks/forum

https://www.hackerrank.com/challenges/constructing-a-number/problem

https://www.hackerrank.com/challenges/sherlock-and-gcd/problem

https://www.hackerrank.com/challenges/identify-smith-numbers/problem
https://www.hackerrank.com/challenges/john-and-gcd-list/problem

https://www.hackerrank.com/challenges/picking-cards/problem

https://www.hackerrank.com/challenges/combo-meal/problem

https://www.hackerrank.com/challenges/number-groups/problem

https://www.hackerrank.com/challenges/points-on-a-line/problem
https://www.hackerrank.com/challenges/most-distant/problem

https://practice.geeksforgeeks.org/problems/print-alternate-elements-of-an-array/1

https://www.hackerrank.com/challenges/mini-max-sum/problem

https://practice.geeksforgeeks.org/problems/ishaan-loves-chocolates/0/

https://practice.geeksforgeeks.org/problems/fighting-the-darkness3949/1/
https://practice.geeksforgeeks.org/problems/multiply-left-and-right-array-sum/0/

https://practice.geeksforgeeks.org/problems/absolute-difference-1/0/

https://practice.geeksforgeeks.org/problems/tough-competitors/0/

https://practice.geeksforgeeks.org/problems/find-first-and-last-occurrence-of-x/0

https://leetcode.com/problems/two-sum/
https://practice.geeksforgeeks.org/problems/last-duplicate-element-in-a-sorted-array/0/

https://www.hackerrank.com/challenges/equality-in-a-array/problem

https://leetcode.com/problems/shuffle-the-array/description/

https://practice.geeksforgeeks.org/problems/print-the-left-element/0

https://practice.geeksforgeeks.org/problems/perfect-array/0
https://www.hackerrank.com/challenges/ctci-array-left-rotation/problem

https://leetcode.com/problems/replace-elements-with-greatest-element-on-right-side/

https://leetcode.com/problems/rotate-array/

https://leetcode.com/problems/maximum-subarray/

https://leetcode.com/problems/sort-colors/
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/

https://leetcode.com/problems/minimum-time-visiting-all-points/

https://leetcode.com/problems/find-common-characters/

https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/
https://leetcode.com/problems/capacity-to-ship-packages-within-d-days/

https://leetcode.com/problems/least-number-of-unique-integers-after-k-removals/

https://leetcode.com/problems/corporate-flight-bookings/

https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/

https://leetcode.com/problems/find-the-duplicate-number/
https://leetcode.com/contest/biweekly-contest-42/problems/average-waiting-time/

https://leetcode.com/contest/weekly-contest-222/problems/maximum-units-on-a-truck/

https://www.hackerrank.com/challenges/summing-the-n-series/problem?isFullScreen=true

https://www.hackerrank.com/challenges/diwali-lights/problem?isFullScreen=true
https://www.hackerrank.com/challenges/die-hard-3/problem?isFullScreen=true

https://www.hackerrank.com/challenges/is-fibo/problem?isFullScreen=true

https://www.hackerrank.com/challenges/k-candy-store/problem?isFullScreen=true

https://www.hackerrank.com/challenges/bus-station/problem?isFullScreen=true
https://www.hackerrank.com/challenges/jim-and-the-jokes/problem?isFullScreen=true

https://www.hackerrank.com/challenges/strange-grid/problem?isFullScreen=true

https://www.hackerrank.com/challenges/closest-number/problem?isFullScreen=true

https://www.hackerrank.com/challenges/primitive-problem/problem?isFullScreen=true
https://www.hackerrank.com/challenges/equations/problem?isFullScreen=true

https://www.hackerrank.com/challenges/binomial-coefficients/problem?isFullScreen=true

https://www.hackerrank.com/challenges/lucy-and-flowers/problem?isFullScreen=true

https://www.hackerrank.com/challenges/divisibility-of-power/problem?isFullScreen=true
https://www.hackerrank.com/challenges/a-weird-function/problem?isFullScreen=true

https://www.hackerrank.com/challenges/arthur-and-coprimes/problem?isFullScreen=true

https://www.hackerrank.com/challenges/ants/problem?isFullScreen=true

https://www.hackerrank.com/challenges/ichigo-and-cubes/problem?isFullScreen=true
https://www.hackerrank.com/challenges/salary-blues/problem?isFullScreen=true

https://www.hackerrank.com/challenges/breaking-sticks/problem?isFullScreen=true

https://www.hackerrank.com/challenges/number-of-subsets/problem?isFullScreen=true

https://www.hackerrank.com/challenges/manasa-loves-maths/problem?isFullScreen=true
https://www.hackerrank.com/challenges/easy-math/problem?isFullScreen=true

https://www.hackerrank.com/challenges/mutual-recurrences/problem?isFullScreen=true

You might also like