Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
*********************************************************************************
Input:
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Output:
1 2 3 4 8 12 16 15 14 13 9 5 6 7 11 10
Input:
1 2 3 4 5 6
7 8 9 10 11 12
13 14 15 16 17 18
Output:
1 2 3 4 5 6 12 18 17 16 15 14 13 7 8 9 10 11
******************************************************************************
Q3. Given an n-by-n matrix of 0’s and 1’s where all 1’s in each row come before all 0’s, find the
most efficient way to return the row with the maximum number of 0’s.
Input
{1,1,1,1},
{1,1,0,0},
{1,0,0,0},
{1,1,0,0},
Output
1000
****************************************************************************
Q4. A Pythagorean triplet is a set of three integers a, b and c such that a 2 + b2 = c2. Given a limit,
generate all Pythagorean Triples with values smaller than given limit.
Input : limit = 20
Output : 3 4 5
8 6 10
5 12 13
15 8 17
12 16 20
A Simple Solution is to generate these triplets smaller than given limit using three nested loop.
For every triplet, check if Pythagorean condition is true, if true, then print the triplet. Time
complexity of this solution is O(limit3) where ‘limit’ is given limit.
An Efficient Solution can print all triplets in O(k) time where k is number of triplets printed. The
idea is to use square sum relation of Pythagorean triplet, i.e., addition of squares of a and b is
equal to square of c, we can write these number in terms of m and n such that,
a = m2 - n 2
b=2*m*n
c = m2 + n 2
because,
a2 = m4 + n4 – 2 * m2 * n2
b2 = 4 * m2 * n2
c2 = m4 + n4 + 2* m2 * n2
We can see that a2 + b2 = c2, so instead of iterating for a, b and c we can iterate for m and n and
can generate these triplets.
***************************************************************************
Q5. Find GCD of two Integers?
*************************************************************************
Q6. Remove all Vowels from a String using Pointers concept?
***********************************************************************
Q7. How to Find LCM of numbers in array.
***********************************************************************
Q8. Find fibonicci series number in an array.
******************************************************************************************************
Q9. Check whether the below program print the below pattern
1111
222
33
****************************************************************************************************
Q10. Fix the error, recompile and match against the output provided.
int main(void)
{
printf(“This is a \”buggy” program\n”);
return 0;
}
***************************************************************************************************
Q11. Code reuse: Convert Binary to Decimal by using the existing function.
void binarytodecimal(number)
{
// Type your code here
}
void main()
{
int num;
scanf(“%d”, &num);
printf(“%d”, binarytodecimal(num);
}
*********************************************************************************************************
Q12. Print the prime numbers from an array up to given value n by using existing function.
**************************************************************************
Q13 To print the trapezium pattern?
1*2*3*4*17*18*19*20
5*6*7*14*15*16
8*9*12*13
10*11
**************************************************************************************
Q14. Print the following Pattern and get the output to match test cases?
To print the pattern like
for n=3
the program should print
1112
3222
3334
************************************************************************************
Q15. Programming Pattern to Print 2*N Number of rows for input Pattern?
3
44
555
6666
555
44
3
****************************************************************************
Q16. Write a program to return a sorted array from two unsorted array?
Examples:
**********************************************************************************
Q17 Find GCD of two Integers? if Numbers are both Positive and Negative?
****************************************************************************************************************
Q18 Write a program that accepts a input n and calculates the factorial of the number using
recursion
*************************************************************************************************************
Q19 Check given number is perfect number or not. Perfect number is a number which is
equal to sum of its divisor. For eg,divisors of 6 are 1,2 and 3. The sum of these divisors is 6.
So 6 is called as perfect number
********************************************************************************
Q 20 Write a program to find the sum of contiguous sub array within a one-dimensional array of
numbers which has the largest sum.
***************************************************************************
Q23 check if two Strings are anagrams of each other. Two strings are anagrams if they are
written using the same exact letters, ignoring space, punctuation, and capitalization. Each
letter should have the same count in both strings. For example, the Army and Mary are an
anagram of each other.
**************************************************************************************************************
Q24 How to program to print first non repeated character from String?
*************************************************************************************************************
********************************************************************************************
Q26
Task
Complete the stub code provided in your editor to print whether or not is weird.
Input Format
Constraints
1<=n<=100
Output Format
Sample Input 0
3
Sample Output 0
Weird
Sample Input 1
24
Sample Output 1
Not Weird
Explanation
*********************************************************************************************
Q27 In the magical land of Byteland, there are three kinds of citizens:
a Bit - 2ms2ms after a Bit appears, it grows up and becomes a Nibble (i.e. it disappears and a Nibble appears)
a Nibble - 8ms8ms after a Nibble appears, it grows up and becomes a Byte
a Byte - 16ms16ms after a Byte appears, it grows up, splits into two Bits and disappears
Chef wants to know the answer to the following question: what would the population of Byteland be immediately
before the time NmsNms if only 1 Bit appeared at time 0ms0ms?
Help him and find the population (number of citizens) of each type.
Input
The first line of the input contains a single integer TT denoting the number of test cases. The description
of TT test cases follows.
The first and only line of each test case contains a single integer NN.
Output
For each test case, print a single line containing three space-separated integers — the number of Bits, Nibbles and
Bytes.
Constraints
1≤T≤1041≤T≤104
1≤N≤1,6001≤N≤1,600
Subtasks
Example Input
Example Output
100
010
Explanation
Immediately before the time 2ms2ms, there is only one Bit. At 2ms2ms, this Bit grows up, so immediately
before 3ms3ms, there is only one Nibble in Byteland.
************************************************************************************
Q28 Given two strings of lowercase English letters, A and B, perform the following operations:
2. Determine if A is lexicographically larger than B (i.e.: does come before in the dictionary?).
3. Capitalize the first letter in A and B and print them on a single line, separated by a space.
Input Format
The first line contains a string A. The second line contains another string B . The strings are comprised of only
For the second line, write Yes if A is lexicographically greater than B otherwise print No instead.
For the third line, capitalize the first letter in both A and B and print them on a single line, separated by a
space.
Sample Input 0
hello
java
Sample Output 0
9
No
Hello Java
Explanation 0
When sorted alphabetically/lexicographically, "hello" precedes "java"; therefore, A is not greater than B and
When you capitalize the first letter of both A and B and then print them separated by a space, you get "Hello
Java".
**********************************************************************************
Q 29
Two strings, a and b, are called anagrams if they contain all the same characters in the same frequencies. For
example, the anagrams of CAT are CAT, ACT, TAC, TCA, ATC, and CTA.
Complete the function in the editor. If a and b are case-insensitive anagrams, print "Anagrams"; otherwise,
Constraints
1<=length(a), length(b)<=50
Output Format
Print "Anagrams" if a and b are case-insensitive anagrams of each other; otherwise, print "Not Anagrams"
instead.
Sample Input 0
anagram
margana
Sample Output 0
Anagrams
Explanation 0
Sample Input 1
anagramm
marganaa
Sample Output 1
Not Anagrams
Explanation 1
Sample Input 2
Hello
hello
Sample Output 2
Anagrams
Explanation 2
************************************************************************************
Q30:
Task
Given the meal price (base cost of a meal), tip percent (the percentage of the meal price being added as
tip), and tax percent (the percentage of the meal price being added as tax) for a meal, find and print the
meal's total cost.
Note: Be sure to use precise values for your calculations, or you may end up with an incorrectly rounded
result!
Input Format
The first line has a double, (the cost of the meal before tax and tip).
The second line has an integer, (the percentage of being added as tip).
The third line has an integer, (the percentage of being added as tax).
Output Format
Print the total meal cost, where is the rounded integer result of the entire bill ( with added tax and tip).
Sample Input
12.00
20
Sample Output
15
***********************************************************************************
Q31
Task
Given an integer, , print its first multiples. Each multiple (where ) should be printed on a new line in the
form: n x i = result.
Input Format
A single integer, .
Constraints
Output Format
Print lines of output; each line (where ) contains the of in the form:
n x i = result.
*******************************************************************************
Q 32:
The religious act which Barney and his friends hold most sacred, XORING the natural numbers in the
given range. This time Barney is a bit busy with picking up some girls, so he asked you to help him. He
gave you two numbers L and R, you have to find if XOR of all the numbers in range L to R (L,R both
inclusive) is odd or even.
Input:
Output:
For each testcase, in the new line print "Odd" if the XOR in the range is odd, else print "Even".
Constraints
1≤T≤106
1≤L≤R≤1018
Sample Input:
14
26
33
23
Sample Output:
Even
Even
Odd
Odd
EXPLANATION:
*********************************************************************************
Q33:
Write a program to print following pattern.
If n=3
12*
1*
**********************************************************************************
Q34 WAP to add a node in linkedlist
Q35 Reverse a string using stack
Q36 Print reverse linkedlist
Q37 Create a linkedlist which contains name and sort them.
Q38 WAP to take 10 values in queue and print it reversely using stack.
}
*************************************************************************************************
Q46 WAP to find out a key in BST using recursion
Int searchKey(node *root, int key){
}
**********************************************************************************************
Q47
Write a program for automatic generation of a password as follow:
Input: Name(First name & Lastname separated by space)
Pin(6 digit pin)
Output: the first alphabet of longer name+ full smaller name+ 6 digit pin+ length of name
in case first name and last name are of equal length
the first alphabet of first name+ full last name+ 6 digit pin+ length of name
Example 1:
Input:
Amit sharma
124001
Output:
SAmit12400113
Example 2:
Input:
Kumar Dilip
301210
Output:
KDilip30121010Q48
*************************************************************************************************
Q48
Write a Program with help of a function in any programming language for printing sum of Even
index position element and Odd index elements that satisfy all the test cases.
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index sum:9
Odd index sum:12
Explanation: Here, n = 6 so there will be 3 even
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd = 2 + 4 + 6 = 12
*******************************************************************************************************
Q49 Program to convert a decimal number to base 17 number
Q53 Rearrange a Linked List by Separating Odd Nodes from the Even Ones.
This series is a mixture of 2 series – all the odd terms in this series form a Fibonacci series and
all the even terms are the prime numbers in ascending order. Now write a program to find the
Nth term in this series.
Hello
Hi
Good Morning
Output:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
++param;
int main(){
strcpy(string, “hello_World”);
myfunc(&string);
myfunc(&string);
printf(“%s\n”, string);
return 0;
Q58. Take some elements in array and store all prime numbers in linkedlist.
Q60. How do you find the middle element of a singly linked list in one pass?