Cheatspeet Dsa
Cheatspeet Dsa
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 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
4 Day 7 Handshake
Number of Steps to
5 Day 7 Reduce a Number to Zero
6 Day 7 Self Dividing Numbers
5 Day 8 Restaurant
4 Day 13 Is Fibo
1 Day 15 Ants
Number of zero-xor
5 Day 15 subsets
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
find the largest number among the three numbers entered by the user.
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 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 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!........
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
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..
Output Format
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
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)
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
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!...................
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
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