Vous êtes sur la page 1sur 8

MINDTREE (AMCAT AUTOMATA) CODING QUESTIONS_2018

PART I :

1. Cell compete
There is a colony of 8 cells arranged in a straight line where each day every cell competes
with its adjacent cells(neighbour).
Each day, for each cell, if its neighbours are both active or both inactive, the cell becomes
inactive the next day,. otherwise itbecomes active the next day.
Assumptions:
The two cells on the ends have single adjacent cell, so the other adjacent cell can be assumsed
to be always inactive.
Even after updating the cell state. consider its pervious state for updating the state of other
cells. Update the cell informationof allcells simultaneously.
Write a fuction cellCompete which takes takes one 8 element array of integers cells
representing the current state of 8 cells and one integer days representing te number of
days to simulate.
An integer value of 1 represents an active cell and value of 0 represents an inactive cell.
program:
int* cellCompete(int* cells,int days)
{
//write your code here
}
//function signature ends
TESTCASES 1:
INPUT:
[1,0,0,0,0,1,0,0],1
EXPECTED RETURN VALUE:
[0,1,0,0,1,0,1,0]
TESTCASE 2:
INPUT:
[1,1,1,0,1,1,1,1,],2
EXPECTED RETURN VALUE:
[0,0,0,0,0,1,1,0]

2. Write a program to return a sorted array from two unsorted array?


Examples:

Input : a[] = {10, 5, 15}


b[] = {20, 3, 2}
Output : Merge List :

1 |AMCAT AUTOMATA CODING QUESTIONS


{2, 3, 5, 10, 15, 20}

Input : a[] = {1, 10, 5, 15}


b[] = {20, 0, 2}
Output : Merge List :
{0, 1, 2, 5, 10, 15, 20}

Please also comment the code down below in other languages.


#include <bits/stdc++.h>
using namespace std;
// Function to merge array in sorted order
void sortedMerge(int a[], int b[], int res[],
int n, int m)
{
// Concatenate two arrays
int i = 0, j = 0, k = 0;
while (i < n) {
res[k] = a[i];
i += 1;
k += 1;
}
while (j < m) {
res[k] = b[j];
j += 1;
k += 1;
}
// sorting the res array
sort(res, res + n + m);
}
// Driver code
int main()
{
int a[] = { 10, 5, 15 };
int b[] = { 20, 3, 2, 12 };
int n = sizeof(a) / sizeof(a[0]);
int m = sizeof(b) / sizeof(b[0]);
// Final merge list
int res[n + m];
sortedMerge(a, b, res, n, m);

2 |AMCAT AUTOMATA CODING QUESTIONS


cout << “Sorted merged list :”;
for (int i = 0; i < n + m; i++)
cout << ” ” << res[i];
cout << “n”;
return 0;
}

3. Pangram Checking
Given a string check if it is Pangram or not. A pangram is a sentence containing every letter
in the English Alphabet.
Examples : The quick brown fox jumps over the lazy dog ” is a Pangram [Contains all the
characters from ‘a’ to ‘z’]
“The quick brown fox jumps over the dog” is not a Pangram [Doesn’t contains all the
characters from ‘a’ to ‘z’, as ‘l’, ‘z’, ‘y’ are missing]
We create a mark[] array of Boolean type. We iterate through all the characters of our
string and whenever we see a character we mark it. Lowercase and Uppercase are
considered the same. So ‘A’ and ‘a’ are marked in index 0 and similarly ‘Z’ and ‘z’ are
marked in index 25.
After iterating through all the characters we check whether all the characters are marked
or not. If not then return false as this is not a pangram else return true.

3 |AMCAT AUTOMATA CODING QUESTIONS


4.

4 |AMCAT AUTOMATA CODING QUESTIONS


5.

6.

6.

5 |AMCAT AUTOMATA CODING QUESTIONS


PART-II

1.Removal of vowel from string


2. GCD of two numbers.
3. Eliminate repeated letters in Array.
4. Various patterns of triangle etc.
5. Star pattern programs
6. string reversal
7. GCD of array of numbers
8. Arrays and strings.
9. Print and count all the numbers which are less than a given key element from our
array.
10. Sorting programs
11. Find whether array is a palindrome or not

12. Write a function that accepts a sentence as a parameter, and returns the same with each
of its words reversed. The returned sentence should have 1 blank space between each pair
of words. Example:
Parameter: “jack and jill went up a hill”
Return Value: “kcaj dna llij tnew pu a llih”

13. Print following pattern


Input:4
1222
2333

6 |AMCAT AUTOMATA CODING QUESTIONS


3444
4555
Input:5
12222
23333
34444
45555
56666

14. Display array dissimilar numbers

Given two arrays and need print (A-B)U(B-A)


17. Mirror image of a matrix.
18. To delete a specified a letter from a given word
19. Input is any odd number
a. If n=3
1 2 3 10 11 12
458 9
67
If n=5
1 2 3 4 5 26 27 28 29 30
6 7 8 9 22 23 24 25
10 11 12 19 20 21
13 14 17 18
15 16

15. Input string : bhanu

Output: bhanu, hanub, anubh, nubha, ubhan

16.Prime numbers upto n numbers

17. ((()) If the no of open and closing braces match ok else print -1 ( matching Parenthesis )

7 |AMCAT AUTOMATA CODING QUESTIONS


18. PRINT THIS PATTERN

1
2 2
333
4444
4444
333
22
1

19. factorial and hcf programs

Pattern program
1234
9 10 11 12
13 14 15 16
5678

20. Pattern program

1
2*2
3*3*3
4*4*4*4
4*4*4*4
3*3*3
2*2
1

8 |AMCAT AUTOMATA CODING QUESTIONS

Vous aimerez peut-être aussi