MindTree Coding section consists of 2 coding-related questions, wherein the student is required to code in any language of their choice.
1. Pattern 1

def mindtree(n) :
j=0
ind=0
for i in range(1, n + 1) :
if i % 2 != 0 :
for j in range(ind + 1, ind + i) :
print(str(j)+"*", end = "")
j = ind + i
print(j)
j += 1
ind = j
else :
ind = ind + i - 1
for j in range(ind, ind - i + 1, -1) :
print(str(j) + "*", end = "")
j = ind - i + 1
print(j)
if __name__ == "__main__" :
n=int(input())
mindtree(n)
2. Pattern 2

//Assume all header files are included
void mindtree(int n)
{
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= i; j++)
printf("%d",i);
printf("\n");
}
for (int i = n - 1; i > 0; i--)
{
for (int j = i; j > 0; j--)
printf("%d",i);
printf("\n");
}
}
int main()
{
int n;
scanf("%d",&n);
mindtree(n);
return 0;
}
Pattern 3 :

//Assume all header files are included
int main()
{
int i, j, num;
scanf("%d", &num);
for(i=1; i<=num; i++)
{
for(j=1; j<=i; j++)
{
if(i==1 || i==num || j==1 || j==i)
{
printf("1");
}
else
{
printf("0");
}
}
printf("\n");
}
return 0;
}
Pattern 4 :

//Assume all header files are included
int main()
{
int i, j, N;
scanf("%d", &N);
for(i=1; i<=N; i++)
{
for(j=i; j<=(i*i); j += i)
{
printf("%-3d", j);
}
printf("\n");
}
return 0;
}
3. Program to find the GCD of two numbers.
See the solution here : https://codeofgeeks.com/gcd-of-two-numbers-using-c/
4. Program to find the LCM of two numbers.
See the solution here : https://codeofgeeks.com/lcm-of-two-numbers-using-c/
5. Write a function to return a sorted array after merging two unsorted arrays, the parameters will be two integer pointers for referencing arrays and two int variable, the length of arrays.
(Hint: use malloc() to allocate memory for 3rd array)
6. Implement Merge Sort using Arrays.
7. Program to print prime numbers between 1 to n.
Follow the approach given here : https://codeofgeeks.com/prime-numbers-in-given-range/
8. Program to reverse the order of words in a given string.
See the solution here : https://codeofgeeks.com/reversing-a-string-using-c/
9. Program to count frequency of digits in an integer.

1 comment on “MindTree Coding Questions”