0% found this document useful (0 votes)
2K views23 pages

Solution - NEOPAT Cycle1

Coa

Uploaded by

veenayak sirohi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views23 pages

Solution - NEOPAT Cycle1

Coa

Uploaded by

veenayak sirohi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

NeoPAT_GLBITM 2024_Screening Test_Set C

Test Summary
No. of Sections: 4
No. of Questions: 24
Total Duration: 120 min

Section 1 - MCQ Easy

Section Summary
● No. of Questions: 10
● Duration: 10 min

Additional Instructions:
None

Q1. What will be the output of the following program?


1 #include <stdio.h>
2
3 int main() {
4 float me = 1.1;
5 double you = 1.1;
6 if(me==you)
7 printf("TATA");
8 else
9 printf("TATA Elxsi");
10
11 return 0;
12 }

TATA

TATA Elxsi

Elxsi

Runtime Error

Q2. What is the worst-case time complexity of inserting a node in a doubly linked list?

O(n log n)

O(log n)

O(n)

O(1)

Q3. What will be the output of the following program?


1 #include<stdio.h>
2
3 int main() {
4 int a = 248755;
5 printf("%d",((a/10)+(a%10)));
6 return 0;
7 }
24130

24880

35478

12563

Q4. In a circular linked list, insertion of a node requires modification of?

One pointer

Two pointers

Three pointers

None of the mentioned options

Q5. Is it possible to create a doubly linked list using only one pointer for every node?

Not Possible

Yes, possible by storing XOR of addresses of previous and next nodes

Yes, possible by storing XOR of current node and next node

Yes, possible by storing XOR of current node and previous node

Q6. What will be the output of the following program?


1 #include<stdio.h>
2
3 int main() {
4 int x = 128;
5 printf ("%d", 1 + x++);
6 return 0;
7 }

128

129

130
131

Q7. What will be the output of the following program?


1 #include <stdio.h>
2
3 int main() {
4 char arr[8] = "Rhombus" ;
5 int i ;
6 for ( i = 0 ; i <= 5 ; i++ )
7 printf("%d ", *arr ) ;
8 }

82 82 82 82 82 82

888888

222222

28 28 28 28 28 28

Q8. The concatenation of two lists can be performed in O(1) time. Which of the following variations of linked list can be used?

Singly linked list

Doubly linked list

Circular doubly linked list

Array implementation of list

Q9. In the linked list, each node contains a minimum of two fields. One field is a data field to store the data second field is?

Pointer to character

Pointer to integer

Pointer to node

None of the mentioned options

Q10. What will be the output of the following program?


1 #include <stdio.h>
2 #include <string.h>
3
4 union sample {
5 int i;
6 float f;
7 char c;
8 double d;
9 char str[20];
10 };
11
11
12 int main() {
13 union sample sm;
14 printf("Memory size occupied by sample : %d", sizeof(sm));
15 return 0;
16 }

Memory size occupied by sample : 2

Memory size occupied by sample : 40

Memory size occupied by sample : 20

Memory size occupied by sample : 24

Section 2 - MCQ Medium

Section Summary
● No. of Questions: 10
● Duration: 10 min

Additional Instructions:
None

Q1. What will be the output of the following program?


1 #include<stdio.h>
2
3 int main() {
4 int arr[5][5][5] = {0};
5 printf("%d", ( &arr+1 - &arr ));
6 return 0;
7 }

Q2. What will be the output of the following program?


1 #include <stdio.h>
2
3 int fun(int n) {
4 if (n == 4)
5 return n;
6 else return 2*fun(n+1);
7 }
8
9 int main() {
10 printf("%d", fun(2));
11 return 0;
12 }
16

12

13

10

Q3. What will be the output of the following program?


1 #include <stdio.h>
2
3 int main() {
4 char s[] = "Learning" ;
5 printf ( "%s", &s[2] ) ;
6 printf ( "\n%s", s ) ;
7 printf ( "\n%s", &s ) ;
8 printf ( "\n%c", s[2] ) ;
9
10 return 0;
11 }

arning
Learning
Learning
Learning

Learning
Learning
Learning
a

Learning
Learning
Learning
Learning

arning
Learning
Learning
a

Q4. Let A be a square matrix of size n x n.

Consider the below program and predict the output for the same.
1 C = 100
2 for i = 1 to n do
3 for j = 1 to n do
4 {
5 Temp = A[i][j] + C
6 A[i][j] = A[j][i]
7 A[j][i] = Temp - C
8 }
9 for i = 1 to n do
10 for j = 1 to n do
11 Output(A[i][j]);

The matrix A itself


Transpose of matrix A

Adding 100 to the upper diagonal elements and subtracting 100 from
diagonal elements of A

None of the mentioned options

Q5. What will be the output of the following program?


1 #include <stdio.h>
2
3 int main() {
4 int n[3][3] = {
5 2, 4, 3,
6 6, 8, 5,
7 3, 5, 1
8 };
9 printf("%d", n[2][2]);
10
11 return 0;
12 }

Q6. What will be the output of the following program?


1 #include <stdio.h>
2
3 int gcd(int a, int b) {
4 if (a == 0)
5 return b;
6 return gcd(b % a, a);
7 }
8
9 int lcm(int a, int b) {
10 return (a / gcd(a, b)) * b;
11 }
12
13 int main() {
14 int a = 15, b = 20;
15 printf("LCM of %d and %d is %d", a, b, lcm(a, b));
16 return 0;
17 }

LCM of 20 and 15 is 35

LCM of 15 and 20 is 60

LCM of 20 and 15 is 60

LCM of 15 and 20 is 61

Q7. What will be the output of the following program?


1 #include <stdio.h>
2
3 int main() {
4 int i;
5 if(i<0)
6 printf("~%x" , -i);
7 else
8 printf("%x" , i);
9
10 return 0;
11 }

Q8. What will be the output of the following program?


1 #include <stdio.h>
2
3 int main() {
4 char *s= "hello";
5 char *p = s;
6 printf("%c %c", 1[p], s[1]);
7 return 0;
8 }

hh

oo

ll

ee

Q9. Which of the following will print the value 2 for the given code?
1 #include <stdio.h>
2
3 int main() {
4 int arr[10][20][30] = {0};
5 arr[3][2][1] = 2;
6 return 0;
7 }

printf("Value at arr[3][2][1]: "%d",*(((a+3)+2)+1));

printf("Value at arr[3][2][1]:arr[3][2][1]);

printf("Value at arr[3][2][1]: %d\n", arr[3][2][1]);


None of the mentioned options

Q10. What will be the output of the following program?


1 #include <stdio.h>
2
3 int main() {
4 int n[2][2] = {2, 4, 6, 8 };
5 int i, j ;
6 for ( i = 0 ; i <= 1 ; i++ )
7 for ( j = 0 ; j <= 1 ; j++ )
8 printf ( "%d %d\n", n[i][j], *( *( n + i ) + j ) ) ;
9
10 return 0;
11 }

44
88
16 16
32 32

22
44
66
88

22
11
22
11

12
34
56
78

Section 3 - Coding Easy

Section Summary
● No. of Questions: 2
● Duration: 50 min

Additional Instructions:
None

Q1. Problem Statement

Bob is attending a seminar on coding, which makes learning more interesting. During the seminar session, he was given a task to
find the frequency of a character.

Help him find the frequency of a character in a given string.

Input Format

The first line of input consists of a string.


The second line consists of the character to find its frequency.

Output Format

The output prints the frequency of the given character.


Constraints

Characters are case-sensitive.

Sample Input Sample Output

Sample Data for analysis 5


a

Sample Input Sample Output

Hello Learn Programming 2


o

Sample Input Sample Output

Hello 0
L

Time Limit: - ms Memory Limit: - kb Code Size: - kb

Q2. Problem Statement

Vanessa is learning about the doubly linked list and is eager to play around with it. She decides to find out how the elements are
inserted in the list and understands that the insertion happens in reverse order. Now she plans to print the original list and reverse
list one below the other.

Help her in implementing the same.

Input Format

The input consists of five integers, separated by space.

Output Format

The output displays the original list and the reversed list one below the other.

Sample Input Sample Output

1 2 3 4 5 5 4 3 2 1
1 2 3 4 5

Sample Input Sample Output

54 65 981 216 987 987 216 981 65 54


54 65 981 216 987

Time Limit: - ms Memory Limit: - kb Code Size: - kb

Section 4 - Coding Medium

Section Summary
● No. of Questions: 2
● Duration: 50 min

Additional Instructions:
None

Q1. Problem Statement

Paul and Peter are friends. They are bored of playing football.
So, Paul gave an array arr of size N to Peter. Peter's task is to find the minimum sum subsequence from the array such that at
least one value among all groups of four consecutive elements is picked.

Help Peter complete his task.

Input Format

The first line of input contains an integer N denoting the size of the array arr.
The next line contains N space-separated integers, denoting the elements of the array.

Output Format

The output prints the minimum sum subsequence such that at least one value among all groups of four consecutive elements is picked.

Constraints

1 <= N <= 50
1 <= arr[i] <= 100

Sample Input Sample Output

8 6
1 2 3 4 5 6 7 8

Sample Input Sample Output

6 35
30 99 63 35 91 64

Time Limit: - ms Memory Limit: - kb Code Size: - kb

Q2. Problem Statement

A statistician collected data on the heights of students in a class and wanted to visualize the distribution using a histogram. The
data consists of the heights of 20 students, with each height value ranging from 1 to 10 (inclusive).

He decides to use a C program to generate the histogram, using pointers.

Function Specifications: void printHistogram(int *hist, int n);

Input Format

The first line of input consists of the number of histogram bars (maximum 20).
The second line of input consists of the heights of students (values between 1 and 10), separated by space.

Output Format

If the input is valid, the program should output the histogram, with each row representing the given input value, using the 'x' format.
If the input is invalid, i.e., not within the valid range, the program should output "Invalid".

Refer to the sample output for a clear understanding.

Constraints

1 ≤ inputValue ≤ 20

Sample Input Sample Output

5 x
1 4 5 3 2 xxxx
xxxxx
xxx
Sample Input Sample Output

4 xxx
3 4 9 10 xxxx
xxxxxxxxx
xxxxxxxxxx
Sample Input Sample Output
0 Invalid

Sample Input Sample Output

21 Invalid

Time Limit: - ms Memory Limit: - kb Code Size: - kb

Could not connect to the reCAPTCHA service. Please check your internet connection and reload to get a reCAPTCHA challenge.
Answer Key & Solution
Section 1 - MCQ Easy
Q1
TATA Elxsi

Solution

No Solution

Q2
O(n)

Solution

No Solution

Q3
24880

Solution

No Solution

Q4
Two pointers

Solution

No Solution

Q5
Yes, possible by storing XOR of addresses of previous and next nodes

Solution

No Solution

Q6
129

Solution

No Solution

Q7
82 82 82 82 82 82

Solution

No Solution

Q8
Circular doubly linked list

Solution

No Solution
Q9
Pointer to node

Solution

No Solution

Q10
Memory size occupied by sample : 24

Solution

No Solution

Section 2 - MCQ Medium


Q1
1

Solution

No Solution

Q2
16

Solution

No Solution

Q3
arning

Learning

Learning

Solution

No Solution

Q4
The matrix A itself

Solution

No Solution

Q5
1

Solution

No Solution

Q6
LCM of 15 and 20 is 60

Solution
No Solution

Q7
0

Solution

No Solution

Q8
ee

Solution

No Solution

Q9
printf("Value at arr[3][2][1]: %d\n", arr[3][2][1]);

Solution

No Solution

Q10
22

44

66

88

Solution

No Solution

Section 3 - Coding Easy


Q1 Test Case

Input Output

This is a good platform to learn 2


l

Weightage - 20

Input Output

coding makes learning easy 1


k

Weightage - 20

Input Output
Join the programming session 3
s

Weightage - 10

Input Output

There are three Different colors Red, Blue and Gre 2


D

Weightage - 40

Input Output

Follow your Heart and Brain 3


r

Weightage - 10

Sample Input Sample Output

Sample Data for analysis 5


a

Sample Input Sample Output

Hello Learn Programming 2


o

Sample Input Sample Output

Hello 0
L

Solution

#include <stdio.h>

int main() {
char str[1000], ch;
int count = 0;

fgets(str, sizeof(str), stdin);


scanf(" %c", &ch); // Read the character, skipping leading whitespace

for (int i = 0; str[i] != '\0'; ++i) {


if (ch == str[i])
++count;
}

printf("%d", count);
return 0;
}
Q2
Test Case

Input Output

1 164 98 61 65 65 61 98 164 1
1 164 98 61 65

Weightage - 20

Input Output

2 36549 851 616 54 54 616 851 36549 2


2 36549 851 616 54

Weightage - 20

Input Output

565 163 65 1 6565 6565 1 65 163 565


565 163 65 1 6565

Weightage - 40

Input Output

56 454 654 84 98 98 84 654 454 56


56 454 654 84 98

Weightage - 20

Sample Input Sample Output

1 2 3 4 5 5 4 3 2 1
1 2 3 4 5

Sample Input Sample Output

54 65 981 216 987 987 216 981 65 54


54 65 981 216 987

Solution

#include <stdio.h>
#include <stdlib.h>

struct Node
{
int data;
struct Node *next;
struct Node *prev;
};
void reverse(struct Node **head_ref);
void push(struct Node** head_ref, int new_data);
void printList(struct Node *node);

void reverse(struct Node **head_ref)


{
struct Node *temp = NULL;
struct Node *current = *head_ref;

/* swap next and prev for all nodes of


doubly linked list */
while (current != NULL)
{
temp = current->prev;
current->prev = current->next;
current->next = temp;
current = current->prev;
}

/* Before changing head, check for the cases like empty


list and list with only one node */
if(temp != NULL )
*head_ref = temp->prev;
}

/* UTILITY FUNCTIONS */
/* Function to insert a node at the beginging of the Doubly Linked List */
void push(struct Node** head_ref, int new_data)
{
/* allocate node */
struct Node* new_node =
(struct Node*) malloc(sizeof(struct Node));

/* put in the data */


new_node->data = new_data;

/* since we are adding at the beginning,


prev is always NULL */
new_node->prev = NULL;

/* link the old list off the new node */


new_node->next = (*head_ref);

/* change prev of head node to new node */


if((*head_ref) != NULL)
(*head_ref)->prev = new_node ;

/* move the head to point to the new node */


(*head_ref) = new_node;
}

/* Function to print nodes in a given doubly linked list


This function is same as printList() of singly linked lsit */
void printList(struct Node *node)
{
while(node!=NULL)
{
printf("%d ", node->data);
node = node->next;
}
}
int main()
{
struct Node* head = NULL;
int val;
for(int i = 0;i<5;i++)
{
scanf("%d", &val);
push(&head, val);
}
printList(head);
reverse(&head);
printf("\n");
printList(head);
return 0;
}

#include <iostream>
using namespace std;

struct Node {
int data;
Node* next;
Node* prev;
};

void reverse(Node** head_ref);


void push(Node** head_ref, int new_data);
void printList(Node* node);

void reverse(Node** head_ref) {


Node* temp = nullptr;
Node* current = *head_ref;

/* swap next and prev for all nodes of


doubly linked list */
while (current != nullptr) {
temp = current->prev;
current->prev = current->next;
current->next = temp;
current = current->prev;
}

/* Before changing head, check for the cases like empty


list and list with only one node */
if (temp != nullptr) {
*head_ref = temp->prev;
}
}

/* UTILITY FUNCTIONS */
/* Function to insert a node at the beginging of the Doubly Linked List */
void push(Node** head_ref, int new_data) {
/* allocate node */
Node* new_node = new Node();

/* put in the data*/


new_node->data = new_data;

/* since we are adding at the beginning,


prev is always NULL */
new_node->prev = nullptr;

/* link the old list off the new node */


new_node->next = *head_ref;

/* change prev of head node to new node */


if (*head_ref != nullptr) {
(*head_ref)->prev = new_node;
}

/* move the head to point to the new node */


*head_ref = new_node;
}

/* Function to print nodes in a given doubly linked list


This function is same as printList() of singly linked lsit */
void printList(Node* node) {
while (node != nullptr) {
cout << node->data << " ";
node = node->next;
}
}

int main() {
Node* head = nullptr;
int val;

for (int i = 0; i < 5; i++) {


cin >> val;
push(&head, val);
}

printList(head);
reverse(&head);
cout << endl;
printList(head);

return 0;
}

Section 4 - Coding Medium


Q1
Test Case

Input Output

14 122
06 83 23 75 84 27 39 49 26 60 70 46 87 65

Weightage - 10

Input Output

25 158
43 45 62 53 18 86 72 59 90 03 14 13 93 20 94 48

Weightage - 20

Input Output

34 197
71 55 42 24 54 67 16 31 10 57 25 50 97 02 58 33

Weightage - 20
Input Output

42 257
43 45 62 53 18 86 72 59 90 03 14 13 93 20 94 48

Weightage - 25

Input Output

50 334
70 46 87 65 79 32 81 28 01 78 43 45 62 53 18 86

Weightage - 25

Sample Input Sample Output

8 6
1 2 3 4 5 6 7 8

Sample Input Sample Output

6 35
30 99 63 35 91 64

Solution

#include <stdio.h>

int min(int a, int b) {


return (a < b) ? a : b;
}

int minSum(int a[], int n) {


if (n <= 4) {
int minval = 100000;
for (int i = 0; i < n; i++) {
minval = min(minval, a[i]);
}
return minval;
}

int dp[n];
dp[0] = a[0];
for (int i = 1; i < 4; i++) {
dp[i] = a[i];
}
for (int i = 4; i < n; i++) {
dp[i] = dp[i - 4] + a[i];
for (int j = 1; j < 4; j++) {
dp[i] = min(dp[i], dp[i - j] + a[i]);
}
}
return min(dp[n - 1], min(dp[n - 2], min(dp[n - 3], dp[n - 4])));
}

int main() {
int n;
scanf("%d", &n);
int a[n];
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
printf("%d", minSum(a, n));

return 0;
}

Q2
Test Case

Input Output

3 xxxx
4 3 2 xxx
xx

Weightage - 10

Input Output

5 xxxxx
5 4 3 9 4 xxxx
xxx
xxxxxxxxx

Weightage - 15

Input Output

8 x
1 3 4 7 2 5 6 9 xxx
xxxx
xxxxxxx
Weightage - 15

Input Output

4 xxxx
4 6 9 10 xxxxxx
xxxxxxxxx
xxxxxxxxxx
Weightage - 10

Input Output

10 xxxx
4 5 6 3 2 1 6 4 3 4 xxxxx
xxxxxx
xxx
Weightage - 20

Input Output

20 xxxx
4 3 2 1 5 6 7 8 9 10 2 3 5 3 5 6 4 3 2 1 xxx
xx
x
Weightage - 20

Input Output

23 Invalid

Weightage - 10

Sample Input Sample Output

5 x
1 4 5 3 2 xxxx
xxxxx
xxx
Sample Input Sample Output

4 xxx
3 4 9 10 xxxx
xxxxxxxxx
xxxxxxxxxx

Sample Input Sample Output

0 Invalid

Sample Input Sample Output

21 Invalid

Solution

#include <stdio.h>

void printHistogram(int *hist, int n);

int main() {
int i, j;
int inputValue, hist_value = 0;

scanf("%d", &inputValue);

if (inputValue > 0 && inputValue <= 20) {


int hist[inputValue];
for (i = 0; i < inputValue; ++i) {
scanf("%d", &hist_value);
if (hist_value >= 1 && hist_value <= 10)
hist[i] = hist_value;
hist_value = 0;
}

int results[10] = {0};


for (j = 0; j < inputValue; j++) {
if (hist[j] == i) {
results[i]++;
}
}
printHistogram(hist, inputValue);
} else {
printf("Invalid");
}

return 0;
}

void printHistogram(int *hist, int n) {


int i, j;
for (i = 0; i < n; i++) {
for (j = 0; j < hist[i]; ++j) {
printf("x");
}
printf("\n");
}
}

You might also like