Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 25

Gen C Elevate

Write a program to check whether the given parenthesis is balanced or not.


Format:
Input:
The input consists of parenthesis.
Output:
The output consists of a result "Balanced" or "Not Balanced".
Example:
Input:
{()}[]
Output:
Balanced
Hint: {}, [] and () are used.
Test Case 1
Input
{()}[]
Output
Balanced
Test Case 2
Input
{{}(})
Output
Not Balanced
Here is an array of piles of chocolates, in every iteration Ayushi chose pile with a maximum
number of chocolates after that square root of chocolate remains and the rest is eaten by
Ayushi. After k iterations find the number of chocolates remaining. 
Input Format
It consists of 3 lines.
first-line contains n ( size of pile)
the second line contains n space-separated integers
the third line contains k.
Output Format
print one integer the total sum of chocolates remaining
Sample Input:
5
25 64 9 4 100
4
Sample Output:
29
Test Case 1
Input
5
25 64 9 4 100
4
Output
30
Test Case 2
Input
6
25 64 9 4 100 98
4
Output
45
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you
from robbing each of them is that adjacent houses have security system connected and it will automatically contact the police if two adjacent houses
were broken into on the same night. Given a list of non-negative integers representing the amount of money of each house, determine the maximum
amount of money you can rob tonight without alerting the police.
Input Format
The first line consists of size of an array
The second line consists of array of elements separated by space
Output Format
The output consists of maximum amount stolen
Constraints
1 <= n <= 1000
1 <= Ai <= 10000
Refer the sample output for formatting
Sample Input
4
11 12 13 11
Sample Output
24
Explanation
Rob house 1 (money = 11) and then rob house 3 (money = 13).
Total amount you can rob = 11 + 13 = 24.
Test Case 1
Input
4
11 12 13 11
Output
24
Given an array that represents elements of an arithmetic progression. One element is missing in the progression, find the missing number.
The first and last element will not be the missing number. Write a program to implement the program with O(log n) time complexity.
Input Format
The first line of input consists of size of an array.
The second line of input consists of elements of an array separated by space.
Output Format
The output consists of the missing number in the series.
Constraints
1 <= N <= 1000
1 <= k <= 50000
Refer the sample output for formatting
Sample Input:
5
1 5 7 9 11
Sample Output:
3
Test Case 1
Input
5
1 5 7 9 11
Output
3
In this program, you are required to implement this function: int SumNumbersDivisible (int m, int n); The function
accepts 2 positive integers ‘m’ and ‘n’ as its arguments. You are required to calculate the sum of numbers divisible by both
3 and 5, between ‘m’ and ‘n’. Include the starting range, exclude the ending range and return the same.
Format:
Input:
The first line consists of an integer value m.
The second line consists of an integer value n.
Output:
We have to obtain the output, that is the sum of the divisible by both 3 and 5.
Constraint:
0 < m <= n
Example:
Input:
12
50
Output:
90
Explanation:
The numbers divisible by both 3 and 5, between 12 and 50 are {15, 30, 45} and their sum is 90.
Test Case 1 Test Case 3 Test Case 5
Input Input Input
12 15 50
50 45 100
Output Output Output
90 45 225
Test Case 2 Test Case 4
Input Input
40 30
90 90
Output Output
180 210
Given a binary array A[] of size N. The task is to arrange the array in increasing order.
Note: The binary array contains only 0's and 1's.

Format:
Input:
The first line of input contains an integer T, denoting the test cases. Every test case contains two lines, the first line is N (size of an array) and the
second line is space-separated elements of an array.
Output:
Space-separated elements of sorted arrays. There should be a new line between the output of every test case.

Constraints:
1 < = T <= 100
1 <= N <= 106
0 <= A[i] <= 1

Example:
Input:
2
5
10110
10
1011111000
Output:
00111
0000111111
Test Case 1
Input
2 5 1 0 1 1 0 10 1 0 1 1 1 1 1 0 0 0
Output
00111
0000111111
Test Case 2
Input
2 10 1 0 0 0 1 0 1 1 0 1 7 1 1 1 1 0 0 0
Output
0000011111
0001111
Abhi is a spy. Its quite natural for him to go on a secret mission. Once You and Abhi were in the same secret mission, when Abhi felt an
urgent need to communicate with Dr. Sabitabatra, who appointed both of you for this mission. The only way to communicate with him was
by sending letters. As both of you were on a secret mission, Abhi will write the letter with some encrypted words which Dr. Sabitabatra was
well aware of . As per the encryption is concerned, the encrypted word will start with the middle character of the string and will be formed
henceforth with the middle characters of the left and right substrings (of the middle character of the word) and so on. Take a look at the
explanation of the sample test case for better comprehension. As the letter was going to be quite long, Abhi wants your help to encrypt
some critical words for him so that he can quickly finish the letter and sent it to Dr. Sabitabatra.
INPUT :
The first line contains an integer T denoting the number of TEST CASES. Each TEST CASE consists of 2 lines. The first line contains an
integer N denoting the length of the word that needs to be encrypted. The second line contains the word that needs to be encrypted.
OUTPUT : N lines where each line will contain the encrypted words
CONSTRAINTS :
1 <= T <= 10
1 <= Length of the string <= 10000
Sample Input:
2
3
abc
4
abcd

Sample Output:
bac
bacd
Test Case 1
Input
2 3 abc 4 abcd
Output
bac
bacd
Test Case 2
Input
1 50 rscdrregojwcpsxpfjlxbksvulbsugewwxaresuhkokbpslskx
Output
ucrcrsdroegjwjxpspfblxskvseslbugxwwraebkuhoklpsksx
Given an array of positive integers. Your task is to find the leaders in the array.
Note: An element of array is leader if it is greater than or equal to all the elements to its right side. Also, the rightmost element is always a leader. 
Input:
The first line of input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the size of array.
The second line contains N space-separated integers A1, A2, ..., AN denoting the elements of the array.
Output:
Print all the leaders.
Constraints:
1 <= T <= 100
1 <= N <= 107
0 <= Ai <= 107
Example:
Input:
3
6
16 17 4 3 5 2
5
12340
5
74573
Output:
17 5 2
40
773
Explanation:
Testcase 3: All elements on the right of 7 (at index 0) are smaller than or equal to 7. Also, all the elements of right side of 7 (at index 3) are smaller than
7. And, the last element 3 is itself a leader since no elements are on its right.
Test Case 1
Input
3 6 16 17 4 3 5 2 5 1 2 3 4 0 5 7 4 5 7 3
Output
17 5 2
40
773
Test Case 2
Input
1 15 12 45 85 96 96 85 324 422 10 14 721 741 852 65 453
Output
852 453
Swap two numbers [C Programming]
Write a program to swap the 2 numbers using logical operator.
The given program compiles successfully but fails to return the desired result for some test cases due to logical errors.
Your task is to fix the code so that it passes all the test cases. 
The code has been commented. Uncomment the code and debug it.
#include <stdio.h>

int main()
{
/*
int i = 65;
int k = 120;
Case 1
printf("%d %d\n", i, k); Input (stdin)
65 120
i = i ~ k; Output (stdout)
k = k ^ i;
printf("%d %d", i, k); 65 120
120 65
return 0;
*/
}
Binary palindrome
Write a program to check whether it’s a binary palindrome or not.
Input format:
The input consist of an integer
Output format:
Print "Yes" or "No"
Sample Input:
9
Sample Output:
Yes
Case 1 Case 2
Input (stdin) Input (stdin)
9 8
Output (stdout) Output (stdout)
Yes No
Dirty Characters
Write a function that takes two strings as arguments and removes the characters from first string which are present in
second string. Note: Treat lowercase and uppercase characters differently. And, space ‘ ‘ is also considered as a
character. Function: removeDirtyChars: function(str, mask_str) This function should return the string after removing
those characters from string str which are present in mask_str.
Input Format
Input is being fetched from the command line arguments. The two arguments are the two strings.
Output Format
Output will be the new string after masking. Case 1 Case 2
Constraints Input (stdin) Input (stdin)
Length of string str>=length of string mask_str.
Length of string str is within range [1,1000]. "Dennis" "Face"
Length of string mask_str is within range [1,100]. "RPD" "focus"
Refer the sample output for formatting Output (stdout) Output (stdout)
 Sample Input:
ennis Fae
 “Dennis Ritchie”
 “RPD”
 (Both the input strings should be in between double quotes).
 Sample Output:
 ennis itchie
Traverse M nodes and delete N nodes
Given head to the singly linear linked list, traversal M nodes and delete N node repeatedly
until you reach the end.
Hint:
Traverse the list M nodes and delete N nodes,
Connect the Mth node and N+1th node directly.
Consider the edge case that the list terminates.
Sample Input:
10
32 Case 1 Case 2
1 2 3 4 5 6 7 8 9 1 Input (stdin) Input (stdin)
Sample Output: 10 5
123678 32 21
1234567891 12345
Output (stdout) Output (stdout)
123678 1245
Make a palindrome
Given a string find the minimum number of appends to make it a palindrome. Rearranging of
the string is not permitted.
Input format
The input consists of string.
Output format
The output prints the minimum number of appends needed
Sample Input:
abcec
Sample Output:
2
Case 1 Case 2
Input (stdin) Input (stdin)
abcec adda
Output (stdout) Output (stdout)
2 0
Check if a given string is a substring of another.
Write a program to check if a given string is a substring of another.
Input Format:
The first input corresponds to the integer.
The remaining consist of string.
Output Format:
Check whether sub string is there or not. If it is print "Yes" or "No".
Sample Input:
Case 1
2
Input (stdin)
Madam mad
2
Madam Mad
Madam mad
Sample Output:
Madam Mad
No
Output (stdout)
Yes
No
Yes
Maximum Exponent
You are given a function,
Int MaxExponents (int a , int b);
You have to find and return the number between ‘a’ and ‘b’ ( range inclusive on both ends)
which has the maximum exponent of 2.
The algorithm to find the number with maximum exponent of 2 between the given range is
Loop between ‘a’ and ‘b’. Let the looping variable be ‘i’.
Find the exponent (power) of 2 for each ‘i’ and store the number with maximum exponent of 2
, let say ‘max’. Set ‘max’ to ‘i’ only if ‘i’ has more exponent of 2 than ‘max’.
Return ‘max’.
Assumption: a <b
Note: If two or more numbers in the range have the same exponents of 2 , return the small
number.
Example
Input:
7
12
Output:
8

Explanation: Case 1 Case 2


Exponents of 2 in: Input (stdin) Input (stdin)
7-0 7 12 4 20
8-3 Output (stdout) Output (stdout)
9-0 8 16
10-1
11-0
12-2
Hence maximum exponent if two is of 8.
Bob encrypt code
Bob has to send a secret code S to his boss. He designs a method to encrypt the code using
two key values N and M. The formula that he uses to develop the encrypted code is shown
below. (((S^N % 10)^M)%1000000007) Write an algorithm to help Bob encrypt the code.
Input Format:
The input consists of three space-separated integers – S, N and M, representing the secret
code, the first key value and the second key value, respectively.
Output Format:
Print an integer representing the code encrypted by Bob. Case 1 Case 2
Constraints: Input (stdin) Input (stdin)
1 < S < 109 Explanation:
234 345
O < N, M < 10 9 S = 2, N = 3, M = 4 and the formula of the
Output (stdout) Output (stdout)
Sample Input: encrypted code is:
4096 1
234 (((S^N % 10)^M)% 1000000007)
Sample Output: (((2^3 % 10)^4)% 1000000007) = 4096
4096 So, the output is 4096.
Q) Equilateral Triangle [C Programming]
The function Equal(int a, int b, int c) accepts three integer value of points a,b and c
respectively. It is supposed to return the values like 0, 1 and 2.
By having this return values, we have to find whether the given points make equilateral or
Isosceles or right angle/scalene triangle. Your task is to use Equal(int a, int b, int c) function
and debug the code so that it passes all test cases.
The code has been commented. Uncomment the code and debug it.
Sample Input:
3 4 5
Output:
Right Angle Triangle/Scalene Triangle
Case 1
Input (stdin)
345
Output (stdout)
Right angle triangle/Scalene triangle
#include<stdio.h> int main()
#include<string.h> {
int a,b,c;
int Equal(int a, int b, int c) scanf("%d%d%d",&a,&b,&c);
{ if (Equal(a, b, c)==1)
/* if (a!=a && b!=c && c!=a) {
{ printf("Equilateral Triangle");
return 1; }
} else if(Equal(a,b,c)==2)
else if( a==b&&a==c&&b!=c) {
{ printf("Isosceles Triangle");
return 2; }
} else if(Equal(a,b,c)==3)
else if(a!=b&&b!=c&&c!=b) {
{ printf("Right angle triangle/Scalene triangle");
return 3; }
} else
else {
{ printf("Not Triangle");
return 0; }
} }
*/
}

You might also like