C Extra Program List
C Extra Program List
7 WAP to find a Fibonacci series up to n terms (n is entered by user) (iterative and recursive)
8 WAP to find a total odd and total even digit of a given number.
9 WAP to find whether a number is Odd or Even without using a % operator.
10 WAP to find a prime number between range (range should be entered by user).
11 WAP to find weather given number is Armstrong number is not.
12 WAP to find Max, Min, Average of n numbers, n should be taken from user and all n value should
be taken from user (Note that you are not allowed to use an array for this)
13 WAP to find a Multiplication of 2 Matrix (dimension and value should be entered by user)
14 WAP to calculate an angle between hour and minute hand. (Hours and minutes should betaken from
user).
15 WAP to convert a Decimal number to BCD.
16 WAP to sort an Array using Bubble sort.
17 WAP to sort an Array using insertion sort.
18 WAP to sort an Array using Selection sort.
19 WAP to sort an Array using Bucket sort.
20 WAP to find a power a^b (without using power and multiplication operation).
21 WAP to sort an Array using Radix sort.
22 Print a following pattern
********* *********
******* **** ****
***** *** ***
*** ** **
* * *
23 WAP to enter an element at specific position into array. (Do not take a new array)
24 WAP to delete an element from array specified by user. if element is not found print a
message “Element is not found” (do not take a new array).
25 WAP to check weather number is present in array or not (using recursion only) and the
function’s syntax is given below
Int isInArray(int a[],int m);
Where int a[] is Array of integer and m is element to be searched.
26 WAP to convert a Binary to Decimal.
27 WAP to find a quotient and reminder of 2 number (bigger number should be divided by lower
number) and you are not allowed to use a division and quotient operator.
28 WAP to convert a Decimal to Binary.
29 Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in
the result must appear as many times as it shows in both arrays and you may
return the result in sorted order.
30 Given an array, rotate the array to the right by k steps, where k is non-negative.Example
1:
1|Pa ge
Department of Computer Science & Engineering
Academic Year 2023-24
C program List
You may assume that each input would have exactly one solution, and you may not use the same
element twice.
Example 1:
Input: strs = ["eat","tea","tan","ate","nat","bat"]
Output: [["bat"],["nat","tan"],["ate","eat","tea"]]
Example 2:
Example 3:
Input Format
The first line of input will contain a single integer T, denoting the number of test cases.
Each test case consists of three integers X,Y, and K, the initial coordinate of Chef, the initial
coordinate of Chefina and the maximum number of coordinates Chef can move in one step.
Output Format
3|Pa ge
Department of Computer Science & Engineering
Academic Year 2023-24
C program List
For each test case, output the minimum number of steps required by Chef to reach Chefina.
47 Chef's dog binary hears frequencies starting from 67 Hertz to 45000 Hertz (both inclusive).
If Chef's commands have a frequency of XX Hertz, find whether binary can hear them or not.
Input Format
The first line of input will contain a single integer TT, denoting the number of test cases.
Each test case consists of a single integer XX - the frequency of Chef's commands in Hertz.
Output Format
For each test case, output on a new line YES, if binary can hear Chef's commands. Otherwise, print
NO.
The output is case-insensitive. Thus, the strings YES, yes, yeS, and Yes are all considered the same.
48 Each contest - there are approximately 1500 - 2000 users who participate for the 1st time and get
rated.
The Chef wanted to tell new users some tricks for their 1st contest:
Before the contest - you don’t have any rating. So even if you make a single submission - you will
become part of the contest rank list and you will get a rating.
If you want your rating to increase - give the entire 3 hours to the contest & don’t quit! If you keep
trying till the end, and the more time you get, the more problems you can solve. That means larger
rating increases!
Do not ask your friends for their code. If you copy paste their code, you will get caught during
plagiarism checks and your rating will be reduced by 275 points, along with a permanent black mark
on your profile.
Now to the problem:
A user just saw the problems and didn’t make any submissions and hence won’t get any rating.
B users who made a submission but could not solve any problem correctly. Thus, after the contest,
they will get a rating in the range 800−1000.
Everyone else could correctly solve at least 11 problems. Thus, they will get a rating strictly greater
than 1000 after the contest.
You need to output the number of new users in the contest who, after the contest, will get a rating
and also the number of new users who will get a rating strictly greater than 1000.
Input Format
Each input file contains of a single line, with three integers, A and B - the number of new users, the
number of users who just saw the problem and didn't make any submission, and the number of users
who made a submission but could not solve any problem correctly.
Output Format
Output two integers separated by a space in a single line - the number of new users who will get a
rating at the end of the contest and the number of new users who will get a rating higher than 1000.
49 In Chef Land, human brain speed is measured in bits per second (bps). Chef has a threshold limit of
XX bits per second above which his calculations are prone to errors. If Chef is currently working at YY
bits per second, is he prone to errors?
Input Format
The only line of input contains two space separated integers X and Y — the threshold limit and the
rate at which Chef is currently working at.
Output Format
If Chef is prone to errors print YES, otherwise print NO.
4|Pa ge
Department of Computer Science & Engineering
Academic Year 2023-24
C program List
You may print each character of the string in uppercase or lowercase (for example, the strings yes,
Yes, yEs, and YES will all be treated as identical).
50 Problem
Chef's son wants to go on a roller coaster ride. The height of Chef's son is X inches while the
minimum height required to go on the ride is H inches. Determine whether he can go on the ride or
not.
Input Format
The first line contains a single integer T - the number of test cases. Then the test cases follow.
The first and only line of each test case contains two integers X and H - the height of Chef's son and
the minimum height required for the ride respectively.
Output Format
For each test case, output in a single line, YES if Chef's son can go on the ride. Otherwise, output NO.
You may print each character of YES and NO in uppercase or lowercase (for example, yes, yEs, Yes
will be considered identical)
51 Chef's computer has NN GB of free space. He wants to save X files, each of size 1 GB and Y files, each
of size 2 GB on his computer. Will he be able to do so?
Chef can save all the files on his computer only if the total size of the files is less than or equal to the
space available on his computer.
Input Format
The first line contains an integer TT, denoting the number of test cases. The T test cases then follow:
The first and only line of each test case contains three integers N,,X,Y, denoting the free-space in
computer, the number of 1 and 2 GB files respectively.
Output Format
For each test case, print YES if Chef is able to save the files and NO otherwise.
You may print each character of the string in uppercase or lowercase (for example, the strings yEs,
yes, Yes and YES will all be treated as identical).
52 Given strings s1, s2, and s3, find whether s3 is formed by an interleaving of s1 and s2.
An interleaving of two strings s and t is a configuration where s and t are divided into n and m
substrings
respectively, such that:
s = s1 + s2 + ... + sn
t = t1 + t2 + ... + tm
|n - m| <= 1
The interleaving is s1 + t1 + s2 + t2 + s3 + t3 + ... or t1 + s1 + t2 + s2 + t3 + s3 + ...
Note: a + b is the concatenation of strings a and b.
53 Given an array nums with n objects colored red, white, or blue, sort them in-place so that objects of
the same color are adjacent, with the colors in the order red, white, and blue.
We will use the integers 0, 1, and 2 to represent the color red, white, and blue, respectively.
You must solve this problem without using the library's sort function.
Example 1:
Note:
A Sudoku board (partially filled) could be valid but is not necessarily solvable.
Only the filled cells need to be validated according to the mentioned rules.
Input: board =
[["5","3",".",".","7",".",".",".","."]
,["6",".",".","1","9","5",".",".","."]
,[".","9","8",".",".",".",".","6","."]
,["8",".",".",".","6",".",".",".","3"]
,["4",".",".","8",".","3",".",".","1"]
,["7",".",".",".","2",".",".",".","6"]
,[".","6",".",".",".",".","2","8","."]
,[".",".",".","4","1","9",".",".","5"]
,[".",".",".",".","8",".",".","7","9"]]
Output: true
55 Given a sorted array of distinct integers and a target value, return the index if the target is found. If
not, return the index where it would be if it were inserted in order.
The same number may be chosen from candidates an unlimited number of times. Two combinations
are unique if the
frequency
of at least one of the chosen numbers is different.
The test cases are generated such that the number of unique combinations that sum up to target is
less than 150 combinations for the given input.
Input
You will be given an integer t(1<=t<=20) representing the number of test cases. A new line follows;
after which the t test cases are given. Each test case starts with a blank line followed by an integer
n(2<=n<=100000), which represents the number of points to follow. This is followed by a new line.
Then follow the n points, each being a pair of integers separated by a single space; followed by a new
line. The X and Y coordinates of each point will be between 0 and 10000 both inclusive.
Output
6|Pa ge
Department of Computer Science & Engineering
Academic Year 2023-24
C program List
For each test case, print the total distance traveled by you from start to finish; keeping in mind the
rules mentioned above, correct to 2 decimal places. The result for each test case must be on a new
line.
58 Given an unsorted integer array nums, return the smallest missing positive integer.
Input: nums = [1,2,0]
Output: 3
Explanation: The numbers in the range [1,2] are all in the array.
59 Given n non-negative integers representing an elevation map where the width of each bar is 1,
compute how much water it can trap after raining.
Example 1:
The height of the tunnel 41 feet and the width can be assumed to be infinite. A box can be carried
through the tunnel only if its height is strictly less than the tunnel's height. Find the volume of each
box that can be successfully transported to the other end of the tunnel. Note: Boxes cannot be
rotated.
Input Format
The first line contains a single integer n, denoting the number of boxes.
N lines follow with three integers on each separated by single spaces –length width and height, and
which are length, width and height in feet of the i-th box.
Output Format
For every box from the input which has a height lesser than 41 feet, print its volume in a separate
line.
61 Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go
outside the signed 32-bit integer range [-231, 231 - 1], then return 0
62 Print a Pascal Triangle
63 Given a triangle array, return the minimum path sum from top to bottom.
For each step, you may move to an adjacent number of the row below. More formally, if you are on
index i on the current row, you may move to either index i or index i + 1 on the next row.
Example 1:
You want to maximize your profit by choosing a single day to buy one stock and choosing a different
day in the future to sell that stock.
Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit,
return 0.
Example 1:
Note that the same word in the dictionary may be reused multiple times in the segmentation.
Example 1:
F(x, y) = x2 + y for 1 ≤ x ≤ A, 1 ≤ y ≤ B
F(x, y) = 2 otherwise
Find the number of integral pairs (x, y) such that F(x, y) is a perfect square.
Input
First and the only line of the input contains two single space separated integers A and B.
Output
Output a single integer indicating the output to the only test case.
69 You are given a 2 × N grid (2 rows, N columns) consisting of lower case English characters (i.e. from
8|Pa ge
Department of Computer Science & Engineering
Academic Year 2023-24
C program List
'a' to 'z'). Two cells are said to be adjacent if they share a side with each other.
The score of such a grid is defined to be the number of unordered pairs of adjacent cells, which have
the same character in them.
You want to rearrange the letters of the grid in such a way that the score is maximized and print the
new rearranged grid. If there are multiple solutions, you can print any.
Input
The first line of the input contains an integer T denoting the number of test cases. The description of
T test cases follow.
The first line of each test case contains an integer N, denoting the number of columns in the grid.
Each of the next two lines contains a string consisting of N lowercase English characters, describing
the first and the second rows of the grid respectively.
Output
For each test case, output two lines, each containing a string of length N. These should describe the
first and the second rows of the rearranged grid.
70 Matrix Multiplication of Different Size.
9|Pa ge