0% found this document useful (0 votes)
51 views8 pages

Automata Fix Prep

Uploaded by

Nan Kumar
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)
51 views8 pages

Automata Fix Prep

Uploaded by

Nan Kumar
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/ 8

8/11/2019 Amcat Automata Fix Questions with Answers 2019 (Latest) -

Amcat Automata Fix Questions with


Answers 2019 (Latest)

Amcat Automata Fix is used to test the candidate’s ability to debug an erroneous code and
x it. Companies like Cognizant, Wipro have recently included Amcat Automata Fix
section in their online test. To know about Cognizant Automata Fix pattern and
questions, click here.

Amcat Automata Fix Questions Pattern

You need to select the language in which you want to attempt this section. You can
choose between C, C++, and Java. The are three types of Amcat Automata Fix
questions asked in this section.

Section name Number of questions Time duration

Automata Fix 7 20 minutes

Logical: You need to x all the logical errors in the given code. To attempt these logical
type of question, you need to have knowledge of concepts such as looping, conditions
https://www.faceprep.in/amcat/automata-fix-questions/ 1/8
8/11/2019 Amcat Automata Fix Questions with Answers 2019 (Latest) -

etc.
Compilation: You need to correct the syntax of the given code without modifying its
logic. The logic along with test cases will be given in the question itself.
Code Reuse: The code reuse type of questions are dif cult when compared to the
logical or compilation type of questions. You need to complete the given code by
reusing the existing functions. There is a tab called “helper code tab” on the test screen.
This can be used to nd out the details of the function/classes provided for reuse.

Amcat Automata Fix Questions – Important instructions

You can use the compile and run option any number of times to check the output of
your code.
You can use printf to debug your code.
The submitted code should be syntactically/logically correct and should pass all the
test cases.
Donot write the main() function as it is not required.
You only need to correct the given code. You don’t have to modify the approach or
incorporate any additional library methods.

Amcat Automata Fix Questions with Answers

Important note:
Faceprep provides information on AMCAT for the bene t of candidates looking for job opportunities. We

are no way in association/partnership with AMCAT or companies hiring through AMCAT. The sole purpose

of the information is to only guide/help candidates identify opportunities and not guarantee opportunities.

AMCAT Automata Fix questions for Cognizant and Wipro

https://www.faceprep.in/amcat/automata-fix-questions/ 2/8
8/11/2019 Amcat Automata Fix Questions with Answers 2019 (Latest) -

1) Find the syntax error in the below code without modifying the logic.

#include
int main()
{
float x = 1.1;
switch (x)
{
case 1: printf("Choice is 1");
break;
default: printf("Invalid choice");
break;
}
return 0;
}

Answer:

#include
int main()
{
int x = 1;
switch (x)
{
case 1: printf("Choice is 1");
break;
default: printf("Invalid choice");
break;
}
return 0;
}

The expression used in the switch must be an integral type (int, char, and enum). Any other
type of expression is not allowed.

https://www.faceprep.in/amcat/automata-fix-questions/ 3/8
8/11/2019 Amcat Automata Fix Questions with Answers 2019 (Latest) -

2) Find the logical error in the below code.

void main () {
int i, j, n = 5;
for(i=1; i<n; i++)
{
for(j=i;j<n;j++);
{
printf("%d", i);
}
printf("\n");
}
}

Solution:

void main () {
int i, j, n = 5;
for(i=1; i<n; i++)
{
for(j=i;j<n;j++)
{
printf("%d", i);
}
printf("\n");
}
}

we use a semicolon in C statement to tell the compiler where’s the end of our statement.
Second for loop executes one time.

3) Complete the below code by reusing the existing function.

Find the index of equilibrium element in the given array. In an array equilibrium element is
the one where the sum of all the elements to the left side is equal to the sum of all the
elements in the right side.

https://www.faceprep.in/amcat/automata-fix-questions/ 4/8
8/11/2019 Amcat Automata Fix Questions with Answers 2019 (Latest) -

Return Value:

1) Return -1 if no equilibrium element is found

2) In case there is more than one equilibrium element, return the element with least index
value.

You are required to complete the given code by reusing the existing function. You can click
on Compile & run anytime to check the compilation/execution status of the program you
can use printf to debug your code. The submitted code should be logically/syntactically
correct and pass all the test cases.

Code approach For the question:

You will need to correct the given implementation.


We do not expect you to modify the approach or incorporate any additional library
methods.

Test Case:

a[] = {1,2,3,4,3,3}. 4 is the equilibrium element since its left side sum (1+2+3) is equal to its
right side sum (3+3)

#include <stdio.h>
// Return the sum of elements from index 0 to (idx - 1)
int left_side_sum(int a[], int n, int idx)
{
int sum = 0, i;
for(i = 0; i < idx; i++)
{
sum += a[i];
}
return sum;
}

// Return the sum of elements from index (idx + 1) to (n - 1)


int right_side_sum(int a[], int n, int idx)
{
int sum = 0, i;
for(i = idx + 1; i < n; i++)

https://www.faceprep.in/amcat/automata-fix-questions/ 5/8
8/11/2019 Amcat Automata Fix Questions with Answers 2019 (Latest) -

{
sum += a[i];
}

return sum;
}

// returns -1 if no equilibrium index found


int findEquilibriumIndex(int a[], int n)
{
// Type your code here
}

int main() {
//code
int a[10], n, i;

// get the elements count


scanf("%d", &n);

// get the array elements


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

int equiIndex = findEquilibriumIndex(a, n);


if(equiIndex != -1) {
printf("%d", a[equiIndex]);
}
return 0;
}

Solution:

// Return the sum of elements from index 0 to (idx - 1)


int left_side_sum(int a[], int n, int idx)
{
int sum = 0, i;
for(i = 0; i < idx; i++)
{
sum += a[i];
}

return sum;
}
https://www.faceprep.in/amcat/automata-fix-questions/ 6/8
8/11/2019 Amcat Automata Fix Questions with Answers 2019 (Latest) -

// Return the sum of elements from index (idx + 1) to (n - 1)


int right_side_sum(int a[], int n, int idx)
{
int sum = 0, i;
for(i = idx + 1; i < n; i++)
{
sum += a[i];
}

return sum;
}

// returns -1 if no equilibrium index found


int findEquilibriumIndex(int a[], int n)
{
// Type your code here
int i;
for(i = 0; i < n; i++)
{
if(left_side_sum(a, n, i) == right_side_sum(a, n, i))
{
return i;
}
}

return -1;
}

int main() {
//code
int a[10], n, i;
// get the elements count
scanf("%d", &n);
// get the array elements
for(i=0; i<n; i++)
{
scanf("%d", &a[i]);
}

int equiIndex = findEquilibriumIndex(a, n);


if(equiIndex != -1) {
printf("%d", a[equiIndex]);
}

return 0;
}

https://www.faceprep.in/amcat/automata-fix-questions/ 7/8
8/11/2019 Amcat Automata Fix Questions with Answers 2019 (Latest) -

Amcat Automata Fix – FAQs

 What is Amcat Automata x?

 What is the pattern of Amcat Automata Fix?

For more such Amcat automata x questions asked in recent drives, check here.

Summary

Name of Reviewer Ayushi Tiwari

Date of Review 2018-09-16

Article Title Amcat Automata Fix Questions

Rating

https://www.faceprep.in/amcat/automata-fix-questions/ 8/8

You might also like