AMCAT Automata Fix Sample Questions and Answers
AMCAT Automata Fix Sample Question Paper
On this page, you will find the Sample AMCAT Automata Fix Questions with Solutions.
In the Automata Fix segment of the AMCAT examination, you will be given a code snippet with an error and you will have to find and fix that error, and make sure that the code works.
This is an optional segment for AMCAT examination, candidates who have a background in CS/IT are more likely to opt for this segment.
AMCAT Automata Fix Sample Question Paper with Solution
What types of questions are asked in AMCAT Automata Fix Section
AMCAT Automata fix Sample Question Paper typically involve identifying and correcting syntax errors, logical errors, or other issues in a given code snippet or algorithm. These questions may cover various programming concepts such as loops, conditionals, data types, functions, and algorithms. They may also require understanding and fixing common errors related to variable assignments, array indices, logic conditions, and function arguments, among others.
Detailed Syllabus:
- Basic programming
- Control Structures
- conditional statements
- Linear data structures
- Advanced data structures
- Sorting and searching algorithms
Some common type of questions that are asked in Automata Fix section are -:
- Given a code snippet that has a logical error, correct the code to produce the expected output.
- Identify and fix the syntax errors in a given code snippet.
- Given an algorithm with a logical flaw, correct the algorithm to produce the correct result.
- Identify and correct the error in a function that is supposed to sort an array in a specific way.
- Given a code snippet with incorrect variable assignments, fix the code to assign the correct values to the variables.
We are not saying that these are the only asked questions, but yes most of the questions come from these concepts only, but the questions are delivered in such a way, that students may find it a bit difficult to fix those codes.
AMCAT Automata Fix detailed Information:
Automata Fix | AMCAT |
---|---|
Number of Questions | 7 Questions |
Time Limit | 20 mins |
Difficulty | Moderate – High |
AMCAT AUTOMATA FIX QUESTIONS 2023
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Sample Questions for AMCAT Automata Fix Question Paper
Question : 1
Check for syntax error/ logical error and correct the error to get the desired output.
review the code for syntax errors and logical mistakes, then make the necessary corrections to achieve the desired output.
print from 1 to n.
The function/method main compiles unsuccessfully due to syntactical error , your task is to debug the program
is to debug the program so that it passes all test case
Int main(){ Int n; cin<<n; for(int i==1;i>=n;i++);{ cout>>i; } }
int main(){ int n; cin>>n; for(int i=1;i<=n;i++);{ cout<<i; } }
Question : 2
Check for syntax error/ logical error and correct the error to get the desired output.
Rectify the error, recompile the code, and debug the code.
#includeInt main(){ Int n; Scanf(%f,”&n”); Printf(%f,”n”); }
#include <stdio.h> int main() { int n; scanf("%d",&n); printf("%d”,n); }
Question : 3
Check for syntax error/ logical error and correct the error to get the desired output.
You’re required Write the logic for printing the ‘nth’ fibonacci number In given function no need to write any boiler code. Only Write Logical part in given section
int fib(int n) { if(n<=1) return n; int prev2 = 0, prev1 = 1, cur; for(int i=2;i<=n;i++){ //write your code here. } return cur; }
int fib(int n) { if(n<=1) return n; int prev2 = 0, prev1 = 1, cur; for(int i=2;i<=n;i++){ cur = prev1+prev2; prev2 = prev1; prev1 = cur; } return cur; }
Question : 4
Review the code for syntax errors and logical mistakes for binary search.
int binarysearch(int arr[], int n, int k){ int start=0; int end=n-1; while (start <= end) { int middle = start+ (end + start) / 2; if (arr[middle] == k) return middle; if (arr[middle] > k) start = middle - 1; else end = middle + 1; } return -1; }
int search(vector& nums, int target) { int l=0; int h=nums.size()-1; int mid=0; while(l<=h){ mid=(h+l)/2; if(nums[mid]==target){ return mid; } else if(nums[mid]<target){ l=mid+1; } else{ h=mid-1; } } return -1; }
Question : 5
You are required to fix logical error if any and required write full logic for the code
Statement:Given two non-decreasingly sorted integer arrays, nums1 and nums2, which are already sorted in non-decreasing order. Additionally, you are given two integers, m and n, representing the number of elements in nums1 and nums2, respectively.
Your task is to merge the elements from nums1 and nums2 into a single array and store the result in nums1. The total number of elements in nums1 should be m + n.
void merge(vector& nums1, int m, vector & nums2, int n) { int j=0; for(int i=m;i<();i++){ //Write your code here. } sort(nums1.begin(),nums1.end()); }
void merge(vector& nums1, int m, vector& nums2, int n) { int j=0; for(int i=m;i<(m+n);i++){ nums1[i]=nums2[j]; j++; } sort(nums1.begin(),nums1.end()); }
FAQs on AMCAT Automata Fix Questions
Question 1: What type of Questions will be asked in Automata Fix Section of AMCAT Exam?
The Automata section of the AMCAT exam is a programming-based section that tests candidates’ knowledge and skills in programming concepts such as loops, conditionals, arrays, strings, and functions.
Question 2: How does AMCAT Automata Fix work?
AMCAT Automata Fix provides a code editor where candidates can write and test their code. The tool checks the code for errors and provides suggestions for fixing them. Candidates can also run their code on sample test cases provided by the tool to see if their code works correctly.
Cognizant GenC Automata Fix Questions and Answers
CTS GenC Automata Fix Questions and Answers
Cognizant GenC Autotmata Fix Questions and Answers has updated its pattern recently (March 2023) . This article provides more details about Cognizant GenC Automata Fix Questions pattern, syllabus and sample questions can found below –
What is Cognizant GenC Automata Fix Section?
- Automata fix is the new section being added by Cognizant GenC in its recruitment drive pattern.
- In this section, there will be 7 code snippets, in which there may be some error, or you may have to code a specific part of the code.
- You can code in any of your desired language like C, C++ or Java. There is no restriction in coding language which you want to choose.
- There is even a possibility that you can code first question in some specific language, and then you are coding the next question in some other specific language.
- This test is basically for judging your interpreting level of code. This section tests, that how good you are in fixing a code written by someone else, or if you can add a small function of your own, in someone’s other code.
Questions of Automata Fix may come from the below concepts. Also, the difficulty level of sections is given below.
- Logical questions: This checks the various logical concepts like Conditions, looping etc.
- Compilation questions: This checks the candidate basic knowledge of syntax and language-specific concepts.
- Code Reuse questions: This is a bit tougher than the logical and compilation based questions. The candidate is required to complete the code using the predefined structure or functions.
Cognizant Automata Fix Test Pattern | CTS GenC Code Debugging Round
Type of Questions | Descriptions |
---|---|
Logical | There may be some logical errors in the code snippet, which the candidate must be able to find and resolve |
Compilation | There may be some compilation error in the code, the candidate must be able to find those syntactical errors and resolve them |
Code Reuse | The candidate must try to reduce the length of the code, without changing the functionality of the code. |
Some more details –
Automata Fix is an assessment solution to check for a computer programmer’s ability to correct an erroneous code and fix it. The test provides a set of programs to the candidate, where they have to either correct them or right new functionality based on the given functions and code. It tests the candidate’s skill of being able to understand code written by someone else, be able to find bugs and also use the code to implement new functionality. This assessment is available across multiple programming languages.
Use Coupon Code “CT10” and get flat 10% OFF on PrepInsta Prime, additionally get:
- 1 months extra on 3 & 6 months plan
- 2 months extra on 12 & 24 months plans
- 3 months extra on 36 & 48 months plan
(Use Coupon Code “CT10” and get 10% off and additional months)
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
COGNIZANT AUTOMATA QUESTIONS 2021
Cognizant GenC Automata Fix Questions and Answers
Question : 1
Check for syntax error/ logical error and correct the error to get the desired output.
The function sortString modifies the input list by sorting its elements depending upon the length of the array, i.e; if the length of the array is even, then the elements are arranged in the ascending order, and if the length of the array is odd, then the elements are arranged in the descending order
The function sortString accepts two arguments – len representing the length of the string, and arr a list of characters, representing the input list respectively.
The function sortString compiles successfully but fails to get the desired results for some test cases due to logical errors. Your task is to fix the code, so that it passess all the test cases
Incorrect Code
void sortArray(int len, int *arr) { int i, max, location, temp, j,k; if(len/2 == 0)//error in this line { for(i=0;i<len;i++) { max=arr[i]; location = i; for(j=i;j<len;j++) if(max<arr[j])//error in this line { max=arr[j]; location = j; } temp=arr[i]; arr[i]=arr[location]; arr[location]=temp; } } else { for(i=0;i<len;i++) { max=arr[i]; location = i; for(j=i;j<len;j++) if(max>arr[j])//error in this line { max=arr[j]; location = j; } temp=arr[i]; arr[i]=arr[location]; arr[location]=temp; } } }Correct Code
void sortArray(int len, int *arr)
{
int i, max, location, temp, j,k;
if(len%2 == 0)
{
for(i=0;i<len;i++)
{
max=arr[i];
location = i;
for(j=i;j<len;j++)
if(max>arr[j])
{
max=arr[j];
location = j;
}
temp=arr[i];
arr[i]=arr[location];
arr[location]=temp;
}
}
else
{
for(i=0;i<len;i++)
{
max=arr[i];
location = i;
for(j=i;j<len;j++)
if(max<arr[j])
{
max=arr[j];
location = j;
}
temp=arr[i];
arr[i]=arr[location];
arr[location]=temp;
}
}
}
Question : 2
Check for syntax error/ logical error and correct the error to get the desired output.
The function maxReplace print space separated integers representing the input list after replacing all the elements of the input list with the sum of all the element of the input list.
The function maxReplace accepts two arguments – size an integer representing the size of the input list and inputList, a list of integers representing the input list respectively.
The function maxReplace compiles unsuccessfully due to compilation errors. Your task is to fix the code so that it passes all the test cases.
void maxReplace(int size, int *inputList)
{
int i,sum=0;
for(i=0;i<size;i++)
{
sum += inputList[i];
}
for(i=0;i<size;i++)
{
sum = inputList[i];//error in this line
}
for(i=0;i<size;i++)
{
printf("%d ",inputList[i]);
}
}
Corrected Code void maxReplace(int size, int *inputList)
{
int i,sum=0;
for(i=0;i<size;i++)
{
sum += inputList[i];
}
for(i=0;i<size;i++)
{
inputList[i]=sum;
}
for(i=0;i<size;i++)
{
printf("%d ",inputList[i]);
}
}
Question : 3
Check for syntax error/ logical error and correct the error to get the desired output.
The function replaceElements is modifying the input list in such a way – if the sum of all the elements of the input list is odd, then all the elements of the input list are supposed to be replaced by 1s, and in case if the sum of all the elements of the input list is even, then the elements should be replaced by 0s.
For example, given the input list [1,2,3,4,5], the function will modify the input list like [1, 1, 1, 1, 1]
The function replaceElements accepts two arguments – size an integer representing the size of the given input list and arr, a list of integers representing the input list.
The function replaceElements compiles successfully but fails to get the desired result for some test cases due to incorrect implementation of the function. Your task is to fix the code so that it passes all the test cases
void replaceElements(int size, int *arr)
{
int i,j;
int sum=0;
for (i=0;i<size;i++)
{
sum+=arr[i];
}
if(size % 2 == 0)//error in this line
{
i=0;
while(i<size)
{
arr[i] = 0;
i += 1;
}
}
else
{
j=1;
while(j<size)
{
arr[j]=1;
j+=1;
}
}
Corrected Code
void replaceElements(int size, int *arr)
{
int i,j;
int sum=0;
for (i=0;i<size;i++)
{
sum+=arr[i];
}
if(sum % 2 == 0)
{
i=0;
while(i<size)
{
arr[i] = 0;
i += 1;
}
}
else
{
j=1;
while(j<size)
{
arr[j]=1;
j+=1;
}
}
Question : 4
Check for syntax error/ logical error and correct the error to get the desired output.
Given n, print 0 to n by identifying whether the n is even or odd.
Test Case : 1
n : 10
Output
0 2 4 6 8 10
Test Case : 2
n : 9
Output
1 3 5 7 9
Incorrect Code
#include <stdio.h>
int main()
{
int n, i;
printf("n : ");
scanf("%d",*n);
if(n%2=0)
{
for(i=0;i<n:i=i+2)
{
printf("%d ",i);
}
}
else
{
for(i=1;i<n;i=i+2)
{
printf("%d ",i);
}
}
return 0;
}
Corrected Code
#include <stdio.h>
int main()
{
int n, i;
printf("n : ");
scanf("%d",&n);
if(n%2==0)
{
for(i=0;i<=n;i=i+2)
{
printf("%d ",i);
}
}
else
{
for(i=1;i<=n;i=i+2)
{
printf("%d ",i);
}
}
return 0;
}
Question : 5
Check whether the below program print the below pattern
Input
enter number of rows : 4
Output
1
22
333
4444
4444
333
22
1
Incorrect Code
#include <stdio.h>
int main()
{
int i,j,n;
printf("Enter the number of rows: ");
scanf("%d",&n);
for(i=1;i<=n;i=i+1)
{
for(j=1;j<=i;j=j+1)
{
printf("%d",i);
}
printf("\n");
}
for(i=n;i>=1;i=i-1)
{
for(j=1;j<=i;j=j-1)
{
printf("%d",i);
}
}
return 0;
}
Corrected Code
#include <stdio.h>
int main()
{
int i,j,n;
printf("Enter the number of rows: ");
scanf("%d",&n);
for(i=1;i<=n;i=i+1)
{
for(j=1;j<=i;j=j+1)
{
printf("%d",i);
}
printf("\n");
}
for(i=n;i>=1;i=i-1)
{
for(j=1;j<=i;j=j+1)
{
printf("%d",i);
}
printf("\n");
}
return 0;
}
Question : 6
Check for syntax/logical error and correct the code for desired output.
In the code you need to find the greatest among three numbers.
Incorrect Code
#include <stdio.h>
int main()
{
int a, b, c, max_num;
printf("Enter the three numbers\n");
printf("First: ");
scanf("%d",&a);
printf("Second: ");
scanf("%d",&b);
printf("Third: ");
scanf("%d",&c);
max_num = (a > b) ? (a > c ? a : c) ? (b > c ? b : c);
printf("Largest number among %d, %d and %d is %d.", a, b, c, max_num);
return 0;
}
Corrected Code
#include <stdio.h>
int main()
{
int a, b, c, max_num;
printf("Enter the three numbers\n");
printf("First: ");
scanf("%d",&a);
printf("Second: ");
scanf("%d",&b);
printf("Third: ");
scanf("%d",&c);
max_num = (a > b) ? (a > c ? a : c) : (b > c ? b : c);
printf("Largest number among %d, %d and %d is %d.", a, b, c, max_num);
return 0;
}
Question : 7
Fix the error, recompile and match against the output provided.
Output : Welcome to “prepinsta”
Incorrect Code
#include<stdio.h>
int main(void)
{
printf("Welcome to \"prepinsta");
return 0;
}
Corrected Code
#include <stdio.h>
int main(void)
{
printf("Welcome to \"prepinsta\"");
return 0;
}
Question : 8
Print the prime numbers from an array up to given value n by using existing function.
int isprime(int num)
{
// type your code here
}
int main()
{
int n, m, arr[100], size=0, i;
scanf(“%d”, &n);
for(m = 2; m <= n; m++)
{
if(isprime(m))
{
arr[size++]= m;
}
}
for(i = 0; i < size; i++)
{
printf(“%d\n”, arr[i]);
}
return 0;
}
Corrected Code
int isprime(int num)
{
int i;
int isprime = 1;
for(i = 2; i <= num / 2; i++)
{
if(num % i == 0)
{
isprime = 0;
break;
}
}
return isprime;
}
Question : 9
Instructions: You are required to write the code. The code should be logically/syntactically correct.
Problem: Write a program in C to display the table of a number and print the sum of all the multiples in it.
Test Cases:
TestCase 1:
Input:
5
Expected Result Value:
5, 10, 15, 20, 25, 30, 35, 40, 45, 50
275
TestCase 2:
Input:
12
Expected Result Value:
12, 24, 36, 48, 60, 72, 84, 96, 108, 120
660
#include
int main()
{
// write your code here
}
Corrected Code
#include <stdio.h>
int main()
{
int n, i, value=0, sum=0;
printf("Enter number : ",n);
scanf("%d",&n);
for(i=1; i<=10; ++i)
{
value = n * i;
printf("%d \t",value);
sum=sum+value;
}
printf("\nsum : %d",sum);
return 0;
}
Question : 10
Question
You have to find the security key from the data transmitted.
Input
The input consists of an integer data, representing the data to be transmitted.
Output
Print an integer representing the security key for the given data.
Example
Input
578378923
Output
783
Explanation
The repeated digits in the data are 7, 8 and 3. So, the security key is 783
#include <stdio.h>
#include <string.h>
int main()
{
char a[50];
int i, j, len, count=0;
scanf("%s",a);
strlen(a);
for(i=0;i<len;i++)
{
for(j=i+1;j<len;j++)
{
if(a[i]=a[j])
{
printf("%c",a[i]);
break;
}
}
}
return 0;
}
Corrected Code
#include <stdio.h>
#include <string.h>
int main()
{
char a[50];
int i, j, len, count=0;
scanf("%s",a);
len = strlen(a);
for(i=0;i<len;i++)
{
for(j=i+1;j<len;j++)
{
if(a[i]==a[j])
{
printf("%c",a[i]);
break;
}
}
}
return 0;
}
Question : 11
Question :
Function/method numberCount accepts three arguments-len, an integer representing the length of input list. arr, a list of integers. and value, an integer value. It returns an integer representing the sum of all the elements of arr that are equal to the given integer value for example
len = 9, arr = [1,2,4,3,2,5,4,1,2], value = 2
function /method will return 6
function/method compiles successfully but fails to return the desired result for some/all cases due to incorrect implementation. Your task is to correct the code so that it passes all test cases.
int numberCount(int len, int* arr, int value)
{
int count = 0;
for(int i =0 ; i < len -1 ; )
{
if(arr[i]==value)
count++;
}
return sum;
}
Corrected Code
int numberCount(int len, int* arr, int value)
{
int count = 0;
for(int i =0 ; i < len ; i++ )
{
if(arr[i]==value)
count++;
}
return count;
}
Question : 12
Question
Print the sum of fibonacci series nth term.
Series : 0, 1, 1, 2, 3, 5, 8, 13
Check syntax/logical error for the code
Example
Input
8
Output
33
Explanation:
The sequence generated by the system will be 0, 1, 1, 2, 3, 5, 8, 13
The sum till 8th term will be 33.
Incorrect Code
#include <stdio.h>
int main()
{
int a=0,b=1,c,n,i=2,sum=0;
printf("n : ");
scanf("%d",&n);
while(i<=n)
{
c=a+b;
a=b;
b=c;
sum=sum+c;
i++;
}
printf("%d",sum);
return 0;
}
Corrected Code
#include <stdio.h>
int main()
{
int a=0,b=1,c,n,i=2,sum=1;
printf("n : ");
scanf("%d",&n);
while(i<n)
{
c=a+b;
a=b;
b=c;
sum=sum+c;
i++;
}
printf("%d",sum);
return 0;
}
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
There has been a critical error on this website.
Login/Signup to comment