Beruflich Dokumente
Kultur Dokumente
CSE_CS104_Practice12_2019
Test Summary
No. of Sections: 2
No. of Questions: 55
Total Duration: 11000 min
Section 1 - MCQs
Section Summary
No. of Questions: 42
Duration: 1000 min
Additional Instructions:
None
Q1. Which of the following statements is correct to create a DataOutputStream to write to a file named out.dat?
java
system
java/system
/java/system
Q3. Which method is used to establish the connection with the specified url in a Driver Manager class?
https://admin.exam.chitkara.edu.in/test/preview?test_id=5b1ffa62-7e65-4864-8951-6872d9906a74&branch_id=7a4955c1-ae99-4872-9896-2126f0bb… 1/46
4/29/2019 CU Exams
public static void deregisterDriver(Driver driver)
Q4. Which of these values is returned by read() method is end of file (EOF) is encountered?
-1
NULL
Q5. ..........is the name of abstract class for streams that dealing with general purpose(non character) input.
Input Stream
Output Stream
Reader
Writer
available()
reset()
flush()
close( )
Reader
Writer
Input Stream
https://admin.exam.chitkara.edu.in/test/preview?test_id=5b1ffa62-7e65-4864-8951-6872d9906a74&branch_id=7a4955c1-ae99-4872-9896-2126f0bb… 2/46
4/29/2019 CU Exams
Output Stream
Q8. Which of these exception is thrown in cases when the file specified for writing is not found?
IOException
FileException
FileNotFoundException
FileInputException
Statement
PreparedStatement
CallableStatment
CalledStatement
FileReader
FileWriter
FileInputStream
InputStreamReader
Q11. Which of following option can be used for the input stream class which uses the character array as a source?
BufferedInputStream
CharArrayReader
FileArrayReader
BufferedReader
Q12. Which method is used to establish the connection with the specified url in a Driver Manager class?
https://admin.exam.chitkara.edu.in/test/preview?test_id=5b1ffa62-7e65-4864-8951-6872d9906a74&branch_id=7a4955c1-ae99-4872-9896-2126f0bb… 3/46
4/29/2019 CU Exams
public static void registerDriver(Driver driver)
Q13. Which of these class contains the methods used to write in a file?
FileStream
FileOutputStream
BufferedOutputStream
FileBufferStream
The JDBC API provides the abstraction and the JDBC drivers provide the
implementation.
New drivers can be plugged-in to the JDBC API without changing the client code.
Q15. Which streams provide functionally for threads to communicate and exchange data between them.
Object
Piped
Pushback
Filtered
DataInputStream
FileInputStream
https://admin.exam.chitkara.edu.in/test/preview?test_id=5b1ffa62-7e65-4864-8951-6872d9906a74&branch_id=7a4955c1-ae99-4872-9896-2126f0bb… 4/46
4/29/2019 CU Exams
BufferedInputStream
PipeInputStream
java.sql.TimeStamp
java.sql.Time
java.io.Time
java.io.TimeStamp
ObjectOutputStream
StringReader
Writer
PrintStream
TRANSACTION_READ_COMMITTED
TRANSACTION_REPEATABLE_READ
TRANSACTION_NONE
TRANSACTION_NONREPEATABLE_READ
executeQuery()
executeUpdate()
getConnection()
prepareCall()
IOException
InterruptedException
SystemException
SystemInputException
Q22. Which of these class is used to read characters and strings in Java from console?
BufferedReader
StringReader
BufferedStreamReader
InputStreamReader
Q23. If there are comparing java.io.BufferedWriter and java.io.FileWriter class, then which capability exist as a method in only one of two ?
java.awt package
java.util package
java.lang package
java.io package
Error
Hi 0.0
null 1.0
Examly 1.0
Hi 0.0
null 1.0
Examly 0.0
Hi 0.0
Hi 1.0
Examly1.0
Q26. What happens if you call the method close() on a ResultSet object?
the method close() does not exist for a ResultSet. Only Connections can be closed.
the ResultSet, together with the Statement which created it and the Connection
from which the Statement was retrieved, will be closed and release all database
and JDBC resources
you will get a SQLException, because only Statement objects can close ResultSets
Slow performance
Q28. Which package contains classes that help in connecting to a database, sending SQL statements to the database, and processing the query
results.
connection.sql
db.sql
https://admin.exam.chitkara.edu.in/test/preview?test_id=5b1ffa62-7e65-4864-8951-6872d9906a74&branch_id=7a4955c1-ae99-4872-9896-2126f0bb… 7/46
4/29/2019 CU Exams
pkg.sql
java.sql
It matches connection requests from the java application with the proper database
driver using communication subprotocol.
AaBaCa
ABCaaa
AaaBaaCaa
AaBaaCaaa
Q31. The OutputStreams includes methods that are designed to perform the following tasks.
i) closing streams ii) flushing streams
iii) reading bytes iv) writing bytes
https://admin.exam.chitkara.edu.in/test/preview?test_id=5b1ffa62-7e65-4864-8951-6872d9906a74&branch_id=7a4955c1-ae99-4872-9896-2126f0bb… 8/46
4/29/2019 CU Exams
ii, iii and iv only
i, ii and iv only
abc
abcd
abcde
true
false
jklmn
jklm
jklmno
jkl
Q36. Which system is of java program uses JDBC, that determine information directly from database system at runtime
Efficient System
Robust System
Active System
Accurate System
TRANSACTION_NONE
https://admin.exam.chitkara.edu.in/test/preview?test_id=5b1ffa62-7e65-4864-8951-6872d9906a74&branch_id=7a4955c1-ae99-4872-9896-2126f0b… 10/46
4/29/2019 CU Exams
TRANSACTION_READ_COMMITTED
TRANSACTION_REPEATABLE_READ
TRANSACTION_NONREPEATABLE_READ
Statement interface
PreparedStatement interface
ResultSet interface
It matches connection requests from the java application with the proper database
driver using communication subprotocol.
Q41. Which type of Statement can be used to execute parameterized queries in JDBC?
Parameterized Statement
Prepared Statement
https://admin.exam.chitkara.edu.in/test/preview?test_id=5b1ffa62-7e65-4864-8951-6872d9906a74&branch_id=7a4955c1-ae99-4872-9896-2126f0b… 11/46
4/29/2019 CU Exams
All kinds of Statements
Q42. What can be happened if we call the deleteRow() method on a ResultSet object in JDBC?
The row you are positioned on is deleted only from the database, not from the
ResultSet .
The row you are positioned on is deleted only from the ResultSet, not from the
database.
The row we are positioned on is deleted from the ResultSet and the database
We will get a compile time error:because we can not delete rows from a ResultSet
Section 2 - CODING
Section Summary
No. of Questions: 13
Duration: 10000 min
Additional Instructions:
None
The collector of Rajpura had ordered a complete revision of the Voters List. He knew that constructing the list of voters is a difficult task,
prone to errors. Some voters may have been away on vacation, others may have moved during the enrollment and so on.
To be as accurate as possible, he entrusted the task to three different officials. Each of them was to independently record the list of voters
and send it to the collector. In Rajpura, every one has an ID number and the list would only list the ID numbers of the voters and not their
names. The officials were expected to arrange the ID numbers in ascending order in their lists.
23 30 42 57 90
21 23 35 57 90 92
21 23 30 57 90
then the final list compiled by the collector would be:
21 23 30 57 90
The ID numbers 35, 42 and 92 which appeared in only one list each do not figure in the final list.
Your task is to help the collector by writing a program that produces the final list from the three given lists.
Input Format
The first line of the input contains 3 integers N1, N2 and N3. N1 is the number of voters in the first list, N2 is the number of voters in the second list
and N3 is the number of voters in the third list. The next N1 lines (lines 2,...,N1+1) contain one positive integer each and describe the first list in
ascending order. The following N2lines (lines N1+2,...,N1+N2+1) describe the second list in ascending order and the final N3 lines
(lines N1+N2+2,...,N1+N2+N3+1) describe the third list in ascending order.
Output Format
The first line of the output should contain a single integer M indicating the number voters in the final list. The next M lines (lines 2,...,M+1) should
contain one positive integer each, describing the list of voters in the final list, in ascending order.
5 6 5 5
23 30 42 57 90 21
21 23 35 57 90 92 23
21 23 30 57 90 30
Sample Input Sample Output
https://admin.exam.chitkara.edu.in/test/preview?test_id=5b1ffa62-7e65-4864-8951-6872d9906a74&branch_id=7a4955c1-ae99-4872-9896-2126f0b… 12/46
4/29/2019 CU Exams
2 3 4 1
22 23 45
24 34 45
56 45 67 68
Time Limit: - ms Memory Limit: - kb Code Size: - kb
Chef has just found a recipe book, where every dish consists of exactly four ingredients. He is going to choose some two dishes and
prepare them for dinner. Of course, he likes diversity and wants to know whether the two dishes are similar. Two dishes are called similar if
at least half of their ingredients are the same. In other words, at least two of four ingredients of the first dish should also be present in the
second dish. The order of ingredients doesn't matter. Your task is to examine T pairs of dishes. For each pair, check if the two dishes are
similar and print "similar" or "dissimilar" accordingly.
Input Format
The first line of the 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 four distinct strings, denoting ingredients needed for the first dish. Each ingredient is represented by a string of length between 2 and 10
inclusive, consisting of lowercase English letters. The second line of each test case describes the second dish in the same format.
Output Format
For each test case, output a single line containing the answer — "similar" if at least half of the ingredients are same, and "dissimilar" otherwise (without
the quotes).
2 [similar, dissimilar]
one two three four
one two three four
gibberish jibberish lalalalala popopopopo
Time Limit: - ms Memory Limit: - kb Code Size: - kb
Rohan is a computer science student and his teacher give him a question:
Given an array nums, and with this there is a sliding window of size k which is moving from the very left of the array to the very right. You
can only see the k numbers in the window. Each time the sliding window moves right by one position. This window return the max number.
Input Format
Output Format
8 7
5 7 -1 -1 -2 -3 2 5 7
2 -1
1
Time Limit: - ms Memory Limit: - kb Code Size: - kb
Q4. CANDIES
Badri is standing at the door of his classroom. There are currently N students in the class, i'th student got Ai candies.
There are still M more students to come inside the class. At every instant, a student enters the class and seated with a student who has
exactly the same number of candies. For each student, Badri shouts YES if such a student with same number of candies is found, NO
otherwise.
Input Format
First line contains an integer T. T test cases follow. First line of each case contains two space-separated integers N and M.
Second line contains N + M space-separated integers, the candies of the students.
Output Format
For each test case, output M new line, Badri's answer to the M students.
Print "YES" (without the quotes) or "NO" (without the quotes) pertaining to the Badri's answer.
https://admin.exam.chitkara.edu.in/test/preview?test_id=5b1ffa62-7e65-4864-8951-6872d9906a74&branch_id=7a4955c1-ae99-4872-9896-2126f0b… 13/46
Explanation (refer sample input & output below for more understanding):
4/29/2019 CU Exams
Initially students with 3 and 2 candies are in the class.
A student with 9 candies enters the class, no student with 9 candies in class. Hence, Badri shouts "NO"
A student with 11 candies enters the class, no student with 11 candies in class. Hence, Badri shouts "NO"
A student with 2 candies enters the class, student with 2 candies found in class. Hence, Badri shouts "YES"
1 NO
2 3 NO
3 2 9 11 2 YES
Input Format
Output Format
In each line should display the input sentences after removing the repeated words leaving only the first occurrence.
Input Format
Output Format
In each line, output the number located in yth position of xth line.
If there is no such position, just print "ERROR!"
5 74
5 41 77 74 22 44 52
1 12 37
4 37 34 36 52 ERROR!
Time Limit: - ms Memory Limit: - kb Code Size: - kb
Input Format
Output Format
https://admin.exam.chitkara.edu.in/test/preview?test_id=5b1ffa62-7e65-4864-8951-6872d9906a74&branch_id=7a4955c1-ae99-4872-9896-2126f0b… 14/46
String should be 1<=s<=1000
4/29/2019 CU Exams
It should contain only alphabets like A-Z-a-z
ABCXYZ ABC
3 XYZ
Input Format
Output Format
Print a long integer denoting the minimum number of miles People must walk to maintain their weight.
5 57
5 3 4 2 1
You are given a grid with N rows (numbered 1 through N) and M columns (numbered 1 through M). Let's denote the cell in row r and column
c by (r, c). Two cells of the grid are adjacent if they share a side.
Some of the cells of this grid contain treasures. You do not know exactly which cells contain them, but an analysis of the grid, called a
treasure hunt map, is available. For each cell (i, j), you are given an integer A_{i, j} with the following meaning:
· A_{i, j} = -1: no information
· A_{i, j} = 0: there is an even number of cells containing a treasure which are adjacent to the cell (i, j)
· A_{i, j} = 1: there is an odd number of cells containing a treasure which are adjacent to the cell (i, j)
A treasure layout is the set of all cells containing treasures. Find the number of possible treasure layouts that are consistent with all the
given information. Since the answer may be large, compute it modulo 10^9 + 7.
Input Format
1. · The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
2. · The first line of each test case contains two space-separated integers N and M.
3. · N lines follow. For each i (1 \le i \le N), the i-th of these lines contains M space-separated integers A_{i, 1}, A_{i, 2}, \ldots, A_{i, M}.
Output Format
For each test case, print a single line containing one integer — the number of treasure layouts modulo 10^9+7.
1 8
3 4
2 3 3 2
2 1 1 1
Sample Input Sample Output
1 0
2 2
-1 1
0 1
Time Limit: - ms Memory Limit: - kb Code Size: - kb
Q10.
https://admin.exam.chitkara.edu.in/test/preview?test_id=5b1ffa62-7e65-4864-8951-6872d9906a74&branch_id=7a4955c1-ae99-4872-9896-2126f0b… 15/46
4/29/2019 CU Exams
After every six months, the department of an organization to maintain the employees list that contains employees name and salary
increment for their performance and give them feedback so that they can improve. To analyse Department required sorted list either on
base of name or salary increment.
To find the employees’s performance by sorting and display the employees's list. If “SalaryIncrementSort” is enter then list should be sorted
with salary increment in the descending order and if “NameSort” is entered as choice, then list should be sorted by name of employees in
alphabetic order. Write a program to complete analysis process.
Input Format
The first line of input will contain numbers of employees, n.
The next lines contain name and of salary increment.
The last line of input contains a choice whether to sort as SalaryIncrementSort or NameSort.
Output Format
Output contains serial no, name and Salary Increment according to sorting choice entered.
Sample Input 1
5
Samar
2500
Tarun
2300
Sara
2600
Gopal
2700
Kanika
3500
SalaryIncrementSort
Sample Output 1
1 Kanika 3500
2 Gopal 2700
3 Sara 2600
4 Samar 2500
5 Tarun 2300
Sample Input 2
6
Trishna
3000
Shanti
2300
Thara
2600
Shanti
3500
Kritka
2000
Latika
3600
NameSort
Sample Output 2
1 Kritka 2000
2 Latika 3600
3 Shanti 2300
4 Shanti 3500
5 Thara 2600
6 Trishna 3000
5 1 Kanika 3500
Samar 2 Gopal 2700
2500 3 Sara 2600
Tarun 4 Samar 2500
Time Limit: - ms Memory Limit: - kb Code Size: - kb
Q11. Comparators are used to compare two objects. In this question, you'll create a comparator and use it to sort an array.
The Player class is provided for you in your editor. It has fields: a String and a integer.
Given an array of Player objects, write a comparator that sorts them in order of decreasing score; if or more players have the same score,
sort those players alphabetically by name. To do this, you must create a Checker class that implements the Comparator interface, then
write an int compare(Player a, Player b) method implementing the Comparator.compare(T o1, T o2) method.
Input Format
https://admin.exam.chitkara.edu.in/test/preview?test_id=5b1ffa62-7e65-4864-8951-6872d9906a74&branch_id=7a4955c1-ae99-4872-9896-2126f0b… 16/46
Input is handled by the locked stub code in the Solution class. The first line contains
4/29/2019 an integer, n, denoting the number of players. Each of the n
CU Exams
subsequent lines contains a player’s name and score, respectively. Constraints players can have the same name. Player names consist of lowercase
English letters.
Output Format
You are not responsible for printing any output. The locked stub code in Solution will create a Checker object, use it to sort the Player array, and print
each sorted element.
Constraints
5 aleksa 150
amy 100 amy 100
david 100 david 100
heraldo 50 aakansha 75
Time Limit: - ms Memory Limit: - kb Code Size: - kb
Q12. A string containing only parentheses is balanced if the following is true: 1. if it is an empty string 2. if A and B are correct, AB is correct, 3. if
A is correct, (A) and {A} and [A] are also correct.
Examples of some correctly balanced strings are: "{}()", "[{()}]", "({()})"
Examples of some unbalanced strings are: "{}(", "({)}", "[[", "}{" etc.
Given a string, determine if it is balanced or not.
Input Format
There will be a line in the input file, each having a single non-empty string.
Output Format
For this case, print 'true' if the string is balanced, 'false' otherwise.
{}() true
Q13. 1. Write a program to find the First Two largest numbers and Last Two largest numbers of a Given array
Input Format
5 // Array Size
1
2
3
4
5
Output Format
https://admin.exam.chitkara.edu.in/test/preview?test_id=5b1ffa62-7e65-4864-8951-6872d9906a74&branch_id=7a4955c1-ae99-4872-9896-2126f0b… 17/46
4/29/2019 CU Exams
Answer Key & Solution
Section 1 - MCQs
Solution
No Solution
Q2 system
Solution
No Solution
Solution
No Solution
Q4 -1
Solution
No Solution
Q5 Input Stream
Solution
No Solution
Q6 flush()
Solution
No Solution
Q7 Reader
Solution
No Solution
Q8 FileNotFoundException
Solution
No Solution
https://admin.exam.chitkara.edu.in/test/preview?test_id=5b1ffa62-7e65-4864-8951-6872d9906a74&branch_id=7a4955c1-ae99-4872-9896-2126f0b… 18/46
4/29/2019 CU Exams
Q9 CallableStatment
Solution
No Solution
Q10 FileReader
Solution
No Solution
Q11 CharArrayReader
Solution
No Solution
Solution
No Solution
Q13 FileOutputStream
Solution
No Solution
Solution
No Solution
Q15 Piped
Solution
No Solution
Q16 BufferedInputStream
Solution
No Solution
Q17 java.sql.TimeStamp
https://admin.exam.chitkara.edu.in/test/preview?test_id=5b1ffa62-7e65-4864-8951-6872d9906a74&branch_id=7a4955c1-ae99-4872-9896-2126f0b… 19/46
4/29/2019 CU Exams
Solution
No Solution
Q18 ObjectOutputStream
Solution
No Solution
Q19 TRANSACTION_NONREPEATABLE_READ
Solution
No Solution
Q20 getConnection()
Solution
No Solution
Q21 IOException
Solution
No Solution
Q22 BufferedReader
Solution
No Solution
Solution
No Solution
Solution
No Solution
Q25 Hi 0.0
null 1.0
https://admin.exam.chitkara.edu.in/test/preview?test_id=5b1ffa62-7e65-4864-8951-6872d9906a74&branch_id=7a4955c1-ae99-4872-9896-2126f0b… 20/46
4/29/2019 CU Exams
Examly 1.0
Solution
No Solution
Solution
No Solution
Solution
No Solution
Q28 java.sql
Solution
No Solution
Solution
No Solution
Q30 AaBaaCaaa
Solution
No Solution
Solution
No Solution
Solution
No Solution
https://admin.exam.chitkara.edu.in/test/preview?test_id=5b1ffa62-7e65-4864-8951-6872d9906a74&branch_id=7a4955c1-ae99-4872-9896-2126f0b… 21/46
4/29/2019 CU Exams
Solution
No Solution
Solution
No Solution
Q35 jklmno
Solution
No Solution
Solution
No Solution
Q37 TRANSACTION_NONREPEATABLE_READ
Solution
No Solution
Solution
No Solution
Solution
No Solution
Solution
No Solution
Solution
https://admin.exam.chitkara.edu.in/test/preview?test_id=5b1ffa62-7e65-4864-8951-6872d9906a74&branch_id=7a4955c1-ae99-4872-9896-2126f0b… 22/46
4/29/2019 CU Exams
No Solution
Q42 The row we are positioned on is deleted from the ResultSet and the database
Solution
No Solution
Section 2 - CODING
Q1 Test Case
Input Output
1 1 1 1
23 23
23
42
Weightage - 20
Input Output
1 2 3 2
23 23
23 45 45
45 56 67
Weightage - 20
Input Output
1 1 3 2
22 22
22 34
22 34 34
Weightage - 20
Input Output
2 2 3 2
23 34 1
1 3 34
1 34 56
Weightage - 20
Input Output
2 2 2 3
1 1 1
2 2 2
3 3 3
Weightage - 20
5 6 5 5
https://admin.exam.chitkara.edu.in/test/preview?test_id=5b1ffa62-7e65-4864-8951-6872d9906a74&branch_id=7a4955c1-ae99-4872-9896-2126f0b…
23 30 42 57 90 21 23/46
4/29/2019 21 23 35 57 90 92 CU23Exams
21 23 30 57 90 30
Sample Input Sample Output
2 3 4 1
22 23 45
24 34 45
56 45 67 68
Solution
Header
import java.util.*;
Collections.sort(voters);
int count = 0;
int i = 0;
while(i < voters.size()){
count = 0;
int cid = voters.get(i);
int k = i;
while(k < voters.size() && cid == voters.get(k)){
k++;
count++;
}
if(count > 1){
validVoters.add(voters.get(i));
}
i = k;
}
Footer
System.out.println(validVoters.size());
for(int v: validVoters){
System.out.println(v);
}
https://admin.exam.chitkara.edu.in/test/preview?test_id=5b1ffa62-7e65-4864-8951-6872d9906a74&branch_id=7a4955c1-ae99-4872-9896-2126f0b… 24/46
4/29/2019 } CU Exams
}
Q2 Test Case
Input Output
Input Output
Weightage - 20
Input Output
1 [similar]
milk cream onion potato
potato cheese cream water
Weightage - 20
Input Output
2 [dissimilar, dissimilar]
one two three four
five seven six four
gibberish jibberish lalalalala popopopopo
Weightage - 20
Input Output
1 [dissimilar]
sss ssd sse ssf
jjj kkk lll hhh
Weightage - 20
2 [similar, dissimilar]
one two three four
one two three four
gibberish jibberish lalalalala popopopopo
Solution
Header
https://admin.exam.chitkara.edu.in/test/preview?test_id=5b1ffa62-7e65-4864-8951-6872d9906a74&branch_id=7a4955c1-ae99-4872-9896-2126f0b… 25/46
4/29/2019 CU Exams
import java.util.*;
public class file {
int t=0;
//System.out.println("number of test case");
t=sc.nextInt();
sc.nextLine();
for(int i=0;i<t;i++) {
int same=0;
String ingredients1[]=new String[4];
String ingredients2[]=new String[4];
//System.out.println("testCase "+i+" line1");
String line1=sc.nextLine();
//System.out.println("testCase "+i+" line2");
String line2=sc.nextLine();
ingredients1=line1.split(" ");
ingredients2=line2.split(" ");
for(int j=0;j<4;j++) {
for(int k=0;k<4;k++) {
if (ingredients1[j].equals(ingredients2[k]))same++;
}
}
if (same>=2)finale.add("similar");
if (same<2) finale.add("dissimilar");
}
System.out.println(finale);
Footer
Q3 Test Case
Input Output
9 6
6 4 -4 2 -1 -4 -6 -2 10 4
4 2
2
Weightage - 30
Input Output
https://admin.exam.chitkara.edu.in/test/preview?test_id=5b1ffa62-7e65-4864-8951-6872d9906a74&branch_id=7a4955c1-ae99-4872-9896-2126f0b… 26/46
4/29/2019 CU Exams
10 8
5 8 2 -2 -7 -7 -4 9 10 11 8
5 2
9
Weightage - 30
Input Output
5 18
11 18 -18 13 -13 18
2 13
13
Weightage - 20
Input Output
7 29
29 20 -20 11 10 -2 -5 20
3 11
11
Weightage - 20
8 7
5 7 -1 -1 -2 -3 2 5 7
2 -1
1
Solution
Header
import java.util.*;
public class file
{
public static int[] maxSlidingWindow(int[] nums, int k) {
Footer
Q4 Test Case
Input Output
1 NO
3 4 NO
5 6 7 1 4 5 2 YES
NO
Weightage - 20
Input Output
2 YES
1 2 NO
3 3 5 NO
3 3 NO
Weightage - 20
Input Output
1 YES
4 6 YES
11 12 5 7 11 11 6 7 8 12 NO
YES
Weightage - 20
Input Output
2 NO
3 3 YES
6 7 11 10 6 7 YES
2 6 NO
Weightage - 20
Input Output
https://admin.exam.chitkara.edu.in/test/preview?test_id=5b1ffa62-7e65-4864-8951-6872d9906a74&branch_id=7a4955c1-ae99-4872-9896-2126f0b… 28/46
4/29/2019 CU Exams
3 NO
3 3 YES
6 7 11 10 6 7 YES
2 6 NO
Weightage - 20
1 NO
2 3 NO
3 2 9 11 2 YES
Solution
Header
import java.util.*;
import java.lang.*;
import java.io.*;
public class file
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
Footer
https://admin.exam.chitkara.edu.in/test/preview?test_id=5b1ffa62-7e65-4864-8951-6872d9906a74&branch_id=7a4955c1-ae99-4872-9896-2126f0b… 29/46
4/29/2019 } CU Exams
}
Q5 Test Case
Input Output
3 Hello world
Hello hello world World My name is Anand
My mY name Name is is is is Anand As per the research
As as per per per the research research
Weightage - 20
Input Output
Weightage - 20
Input Output
Weightage - 20
Input Output
Weightage - 20
Input Output
Weightage - 20
Solution
Header
https://admin.exam.chitkara.edu.in/test/preview?test_id=5b1ffa62-7e65-4864-8951-6872d9906a74&branch_id=7a4955c1-ae99-4872-9896-2126f0b… 30/46
4/29/2019 CU Exams
import java.util.*;
public class file{
public static void main(String args[]){
Scanner in = new Scanner(System.in);
Footer
}
}
Q6 Test Case
Input Output
0 ERROR!
1
1 1
Weightage - 20
Input Output
4 75
4 12 13 14 15
3 56 57 53
5 38 49 50 63 75
Weightage - 20
Input Output
2 ERROR!
2 34 23
3 45 54 65
1
https://admin.exam.chitkara.edu.in/test/preview?test_id=5b1ffa62-7e65-4864-8951-6872d9906a74&branch_id=7a4955c1-ae99-4872-9896-2126f0b… 31/46
4/29/2019 CU Exams
Weightage - 20
Input Output
4 75
4 12 13 14 15 12
3 56 57 53
5 38 49 50 63 75
Weightage - 20
Input Output
3 12
4 12 13 14 15 57
3 56 57 53 50
5 38 49 50 63 75
Weightage - 20
5 74
5 41 77 74 22 44 52
1 12 37
4 37 34 36 52 ERROR!
Solution
Header
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
Footer
}
}
Q7 Test Case
Input Output
ILOVEINDIA EIND
4 VEIN
Weightage - 20
Input Output
LAZYDOGJUMPSOVERTHEFOX AZYDOGJUMP
10 ZYDOGJUMPS
Weightage - 20
Input Output
ONE E
1 O
Weightage - 20
Input Output
AAAAAAAAAAABBBBBBBBBBB AAAAAA
6 BBBBBB
Weightage - 20
Input Output
entersampleinput ample
5 tersa
Weightage - 20
https://admin.exam.chitkara.edu.in/test/preview?test_id=5b1ffa62-7e65-4864-8951-6872d9906a74&branch_id=7a4955c1-ae99-4872-9896-2126f0b… 33/46
4/29/2019 CU Exams
ABCXYZ ABC
3 XYZ
Solution
Header
import java.util.*;
Footer
System.out.println(getSmallestAndLargest(s, k));
}
}
Q8 Test Case
Input Output
https://admin.exam.chitkara.edu.in/test/preview?test_id=5b1ffa62-7e65-4864-8951-6872d9906a74&branch_id=7a4955c1-ae99-4872-9896-2126f0b… 34/46
4/29/2019 CU Exams
5 181
9 8 6 7 5
Weightage - 30
Input Output
4 71
5 4 7 6
Weightage - 30
Input Output
6 151
9 7 1 5 2 6
Weightage - 40
5 57
5 3 4 2 1
Solution
Header
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class file {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] calories = new int[n];
for(int k=0; k< n; k++){
calories[k] = in.nextInt();
}
Arrays.sort(calories);
long sum = 0;
for(int i = n-1; i>=0; i--) {
sum += (long)calories[i]*Math.pow(2, (n-1-i));
}
System.out.println(sum);
Footer
https://admin.exam.chitkara.edu.in/test/preview?test_id=5b1ffa62-7e65-4864-8951-6872d9906a74&branch_id=7a4955c1-ae99-4872-9896-2126f0b… 35/46
4/29/2019 CU Exams
}
}
Q9 Test Case
Input Output
1 8
2 3
1 1 -1
1 1 1
Weightage - 20
Input Output
1 2
3 2
1 0
0 1
Weightage - 20
Input Output
1 8
3 3
2 2 2
1 1 1
Weightage - 30
Input Output
1
2 3 Execution Timed Out
2 2
1 1
Weightage - 30
1 8
3 4
2 3 3 2
2 1 1 1
1 0
2 2
-1 1
0 1
Solution
Header
import java.io.OutputStream;
https://admin.exam.chitkara.edu.in/test/preview?test_id=5b1ffa62-7e65-4864-8951-6872d9906a74&branch_id=7a4955c1-ae99-4872-9896-2126f0b… 36/46
import java.io.InputStream;
po t ja
import a. o. putSt ea ;
java.io.InputStream;
4/29/2019 import java.io.PrintWriter; CU Exams
import java.util.Arrays;
import java.io.BufferedInputStream;
import java.util.ArrayList;
int t = in.scanInt();
while (t-- > 0) {
int n = in.scanInt();
int m = in.scanInt();
int arr[][] = new int[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
arr[i][j] = in.scanInt();
}
}
int gauss(ArrayList<int[]> a) {
int n = (int) a.size();
int m = (int) a.get(0).length;
https://admin.exam.chitkara.edu.in/test/preview?test_id=5b1ffa62-7e65-4864-8951-6872d9906a74&branch_id=7a4955c1-ae99-4872-9896-2126f0b… 37/46
for (int i = 0; i < a.get(sel).length; ++i) {
o (
for t i
(int 0; i < a.get(se ). e gt ; ++i)
a.get(sel).length; ) {
4/29/2019 int temp = a.get(sel)[i]; CU Exams
a.get(sel)[i] = a.get(row)[i];
a.get(row)[i] = temp;
}
if (a.get(row)[col] == 0) continue;
where[col] = row;
for (int i = 0; i < n; ++i) {
if (i != row && a.get(i)[col] == 1) {
for (int k = 0; k < a.get(i).length; k++) {
a.get(i)[k] ^= a.get(row)[k];
}
}
}
++row;
}
https://admin.exam.chitkara.edu.in/test/preview?test_id=5b1ffa62-7e65-4864-8951-6872d9906a74&branch_id=7a4955c1-ae99-4872-9896-2126f0b… 38/46
I *= 10;
I 0;
10;
4/29/2019 I += n - '0'; CU Exams
n = scan();
}
}
return neg * I;
}
Footer
Input Output
5 1 puran 3200
ram 2 ram 2000
2000 3 raman 3100
sham 4 sham 2100
Weightage - 40
Input Output
6 1 taran 2100
pam 2 jam 2000
https://admin.exam.chitkara.edu.in/test/preview?test_id=5b1ffa62-7e65-4864-8951-6872d9906a74&branch_id=7a4955c1-ae99-4872-9896-2126f0b…
1000 3 shweta 1500 39/46
4/29/2019 jam CU4 Exams
kawal 1400
Weightage - 30
Input Output
5 1 deep 2100
kamal 2 kamal 1500
1500 3 preet 1000
samar 4 samar 1000
Weightage - 30
5 1 Kanika 3500
Samar 2 Gopal 2700
2500 3 Sara 2600
Tarun 4 Samar 2500
Solution
import java.io.*;
import java.util.*;
import java.lang.*;
class File{
public static void main(String[] args) throws IOException{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
List<Employee> l1=new LinkedList<Employee>();
int siz=Integer.parseInt(reader.readLine());
for(int i=0;i<siz;i++) {
String name=reader.readLine();
int SalaryIncrement=Integer.parseInt(reader.readLine());
l1.add(new Employee(name, SalaryIncrement));
}
String choice=reader.readLine();
if(choice.equals("SalaryIncrementSort"))
Collections.sort(l1,new SortBySalary());
else if(choice.equals("NameSort")) {
Collections.sort(l1,new SortByName());
}
Iterator <Employee>it=l1.iterator();
int i=1;
while(it.hasNext())
{
Employee obj=(Employee)it.next();
System.out.println(i++ +" "+obj.name+" "+obj.SalaryIncrement);
}
}
}
class Employee{
int SalaryIncrement;
String name;
Employee(String name,int SalaryIncrement){
this.SalaryIncrement=SalaryIncrement;
this.name=name;
}
public String toString(){
return this.name+" "+this.SalaryIncrement;
}
https://admin.exam.chitkara.edu.in/test/preview?test_id=5b1ffa62-7e65-4864-8951-6872d9906a74&branch_id=7a4955c1-ae99-4872-9896-2126f0b…
} 40/46
4/29/2019 class SortBySalary implements Comparator<Employee>{ CU Exams
public int compare(Employee n1,Employee n2){
// if(n1.SalaryIncrement==n2.SalaryIncrement)
// return (n1.name.compareTo(n2.name));
// else
return -(n1.SalaryIncrement-n2.SalaryIncrement);
}
}
class SortByName implements Comparator<Employee>{
public int compare(Employee n1,Employee n2) {
// if((n1.name).equals(n2.name))
// return -(n1.SalaryIncrement-n2.SalaryIncrement);
// else
return ( n1.name.compareTo(n2.name));
}
}
Input Output
5 kripa 150
arpit 100 arpit 100
pinku 100 pinku 100
pinku 50 ayesha 75
Weightage - 25
Input Output
5 a 150
a 100 a 100
b 100 b 100
c 50 a 75
Weightage - 25
Input Output
3 a 150
a 100 a 100
a 75 a 75
a 150
Weightage - 25
Input Output
3 c 99
q 99 q 99
w 99 w 99
c 99
Weightage - 25
5 aleksa 150
amy 100 amy 100
david 100 david 100
heraldo 50 aakansha 75
https://admin.exam.chitkara.edu.in/test/preview?test_id=5b1ffa62-7e65-4864-8951-6872d9906a74&branch_id=7a4955c1-ae99-4872-9896-2126f0b… 41/46
4/29/2019 CU Exams
Solution
Header
import java.util.*;
return 0;
}
}
Footer
class Player{
String name;
int score;
class Solution {
Input Output
({()}) true
Weightage - 25
Input Output
()[} false
Weightage - 25
Input Output
[(])}}{{ false
Weightage - 25
Input Output
()[]{} true
Weightage - 25
{}() true
Solution
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.util.ArrayList;
https://admin.exam.chitkara.edu.in/test/preview?test_id=5b1ffa62-7e65-4864-8951-6872d9906a74&branch_id=7a4955c1-ae99-4872-9896-2126f0b… 43/46
4/29/2019 class File CU Exams
{
public static boolean isBallanced(String paranString)
{
List<String>closingParan = Arrays.asList("}", ")", "]");
boolean isBallanced = true;
ArrayList<String> stack = new ArrayList<String>();
if(paranString.length()>0){
for(int i = 0;i<paranString.length();i++){
String paran = paranString.substring(i,i+1);
if(stack.size() == 0 && closingParan.contains(paran)){
isBallanced=false;
break;
}else{
if(paran.equals("{") || paran.equals("(") || paran.equals("[")){
stack.add(paran);
}else{
String stackParan = stack.get(stack.size()-1);
if((stackParan.equals("{") && paran.equals("}")) || (stackParan.equals("(") && paran.equals(")")
{
stack.remove(stack.size()-1);
}else{
isBallanced = false;
break;
}
}
}
}
}
if(stack.size()>0) isBallanced = false;
return isBallanced;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
if(isBallanced(sc.nextLine())){
System.out.println("true");
}else{
System.out.println("false");
}
}
}
Input Output
Weightage - 20
Input Output
Weightage - 20
https://admin.exam.chitkara.edu.in/test/preview?test_id=5b1ffa62-7e65-4864-8951-6872d9906a74&branch_id=7a4955c1-ae99-4872-9896-2126f0b… 44/46
4/29/2019 CU Exams
Input Output
Input Output
Weightage - 20
Solution
import java.util.Scanner;
public class file
{
public static void main(String[] args)
{
int n, l1, l2, temp;
Scanner s = new Scanner(System.in);
System.out.print("Enter Array Size");
n = s.nextInt();
if(n > 1)
{
int a[] = new int[n];
System.out.println("Enter the Elements");
for(int i = 0; i < n ; i++)
{
a[i] = s.nextInt();
}
for(int i = 0; i < n; i++)
{
for(int j = i + 1; j < n; j++)
{
if(a[i] < a[j])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
System.out.println("First two Largest two numbers are:"+a[0]+" and "+a[1]);
System.out.println("Last two Largetst two Numbers are:"+a[n-2]+"and"+a[n-1]);
}
else
{
https://admin.exam.chitkara.edu.in/test/preview?test_id=5b1ffa62-7e65-4864-8951-6872d9906a74&branch_id=7a4955c1-ae99-4872-9896-2126f0b… 46/46