AMCAT Coding Questions and Answers 2024, Get Amcat Coding Questions

AMCAT Coding Questions and Answers 2024 | AMCAT Coding Questions with Solutions | AMCAT Coding Interview Questions | Amcat Coding Questions | Amcat Coding Questions and Answers Pdf 

AMCAT Coding Questions and Answers 2024: The Coding Questions and Answers is very important in the IT Sector and Private Job Sector. Now days candidates are mostly interested in the off-Campus drive and private jobs. Eagerly prepare for the Coding Interview, Assessment Test, and attend the many samples online test for Private jobs. Following of the hiring, AMCAT issued the Off Campus Drive for eligible and capable candidates. The AMCAT Hiring selection process coding test, technical test etc., The Coding Interview round will be asked many questions through sample of C, C++, Java, Python Programming Languages. Thoroughly prepare for the AMCAT Coding Interview. Here we uploaded major common AMCAT Coding Questions and AMCAT Coding Interview Questions. Applicants must prepare AMCAT Coding Questions and Answers.

You have spent a time to solve the AMCAT Coding Questions while using this page. The Very AMCAT questions consist of each programming languages. So, candidates prepare all programming languages on one by one. Variety of the sample Amcat Coding Questions makes confidence to attend the AMCAT Hiring. Once you have selected in the AMCAT coding Interview round, you will be move on further selection process. The coding interview round is main part of the AMCAT Hiring. Candidates focused to prepare AMCAT Coding Questions and AMCAT Coding Interview Questions and Answers.

Amcat Coding Questions and Answers 

Question 1: Foundation Installation 

Fountains are installed at every position along a one-dimensional garden of length n. Array locations[] represents the coverage limit of these fountains. The ith fountain (where 1sisn) has a coverage limit of locations[i] that can range from the position max((i – locations[i]), 1) to min((i + locations[i]), n ). In other words, the h fountains do not reach outside the boundaries of the garden. In the beginning,all the fountains are switched off. Determine the minimum number of fountains that need to be activated to cover the n length garden by water.

Example

  • n = 3
  • locations[] = {0, 2, 13, then
    • For position 1: locations[1] = 0, max((1 – 0),
      • 1) to mini (1+0), 3) gives range = 1 to 1
    • For position 2: locations[2] = 2, max((2-2),
      • 1) to min( (2+2), 3) gives range = 1 to 3
    • For position 3: locations[3] = 1, max( (3-1),
      • 1) to min( (3+1), 3) gives range = 2 to 3

For the entire length of this garden to be covered, only the fountain at position 2 needs to be activated.

Function Description

Complete the function fountainActivation in the editor below.

fountainActivation has the following Parameter:

  • int locations[n]: the fountain locations

Returns

  • int: the minimum number of fountains that must be activated

Constraints

  • 1<_n<_ 10^5
  •  O<_locations[i] <_ mini (n,100) (where 1 <_1<_10^5)

► Input Format For Custom Testing

Sample Case 0

Sample Input For Custom Testing

  • 3 ->locations[] size n = 3
  • 1 ->locations[] [1, 1, 1
  • 1 ->Sample Output

Sample Output

  • 1

Explanation

Here, locations = {1, 1, 13

  • For position 1: locations[1] = 1, maxi (1 -1), 1) to min((1+1), 3) gives range = 1 to 2
  • For position 2: locations[2] = 1, max( (2 -1), 1) to min( (2+1), 3) gives range = 1 to 3
  • For position 3: locations[3] = 1, max((3 -1), 1) to min((3+1), 3) gyes range = 2 to 3

If the 2nd fountain is active, the range from position 7 to 3 will be covered. The total number of fountains needed is 1.

C++ PROGRAM 

#include<bits/stdc++.h>

#define ll long long

using namespace std;

bool compare(pair < int, int > A, pair < int, int > B)

{

  if (A.first = B.first)

    return A.second < B.second;

  return A.first < B.first;

}

int solve(int location[], int n)

{

  pair < int, int > range[n];

  for (int i = 0; i < n; i++)

  {

    int id = i + 1;

    range[i].first = max(1, id - location[i]);

    range[i].second = min(n, id + location[i]);

  }

  sort(range, range + n, compare);

  int i = 0;

  int ans = 0;

  while (i < n)

  {

    pair < int, int > p = range[i];

    ans++;

    while (i + 1 < n && range[i].first == range[i + 1].first)

    {

      p.second = max(p.second, range[i + 1].second);

      i++;

    }

    //cout<<p.second<<" "<<i<<endl;

    while (i < n && range[i].second <= p.second)

      i++;

    //cout<<p.second<<" "<<i<<endl; } return ans; } int main() { int n; cin >> n;

  int location[n];

  for (int i = 0; i < n; i++) cin >> location[i];

  cout << solve(location, n) << endl;

  return 0;

}

JAVA PROGRAM 

import java.util.*;

class Main {

    static int minCntFoun(int a[], int N) {

        int[] dp = new int[N + 1];
        Arrays.fill(dp, -1);

        // Mark the reachable indices for each fountain
        for (int i = 0; i < N; i++) {
            int left = Math.max(i - a[i], 0);
            int right = Math.min(i + a[i]+1, N);
            dp[left] = Math.max(dp[left], right);
        }

        int cntfount = 1;
         int idxRight = dp[0];
        int idxNext = 0;

        // Traverse the reachable indices and activate fountains
        for (int i = 0; i < N; i++) {

            idxNext=Math.max(idxNext,dp[i]);
            if(i==idxRight){
            cntfount++;
            idxRight = idxNext;
            }

        }

        return cntfount;
    }

    // Driver Code
    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        int n = scan.nextInt();
        int[] location=new int[n];
        for(int i=0;i < n;i++){
            location[i]=scan.nextInt();

        }

        System.out.print(minCntFoun(location, n));
    }
}

Ouestion 2: Collecting Candies

Problem Description

Question:- Krishna loves candies a lot, so whenever he gets them, he stores them so that he can eat them later whenever he wants to.

He has recently received  N boxes of candies each containing Ci candies where Ci represents the total number of candies in the ith box. Krishna wants to store them in a single box. The only constraint is that he can choose any two boxes and store their joint contents in an empty box only. Assume that there are an infinite number of empty boxes available.

At a time he can pick up any two boxes for transferring and if both the boxes contain X and Y number of candies respectively, then it takes him exactly X+Y seconds of time. As he is too eager to collect all of them he has approached you to tell him the minimum time in which all the candies can be collected.

Input Format:

  • The first line of input is the number of test case T
  • Each test case is comprised of two inputs
  • The first input of a test case is the number of boxes N
  • The second input is N integers delimited by whitespace denoting the number of candies in each box

Output Format: Print minimum time required, in seconds, for each of the test cases. Print each output on a new line.

Constraints:

  • 1 < T < 10
  • 1 < N< 10000
  • 1 < [Candies in each box] < 100009
S. No. Input Output
1 1
4
1 2 3 4
19
2 1
5
1 2 3 4 5
34

Explanation for sample input-output 1:

4 boxes, each containing 1, 2, 3 and 4 candies respectively.Adding 1 + 2 in a new box takes 3 seconds.Adding 3 + 3 in a new box takes 6 seconds.Adding 4 + 6 in a new box takes 10 seconds.Hence total time taken is 19 seconds. There could be other combinations also, but overall time does not go below 19 seconds.

Explanation for sample input-output 2:

5 boxes, each containing 1, 2, 3, 4 and 5 candies respectively.Adding 1 + 2 in a new box takes 3 seconds.Adding 3 + 3 in a new box takes 6 seconds.Adding 4 + 6 in a new box takes 10 seconds.Adding 5 + 10 in a new box takes 15 seconds.Hence total time taken is 34 seconds. There could be other combinations also, but overall time does not go below 33 seconds.

C PROGRAM 

#include<stdio.h>
#include<string.h>
int main() 
{
    int i,j;
    int num_box=0,k=0,sum=0,times=0,tst_case,temp=0;
    long c[10000],s[10000];
    printf("Enter the number of test case:");
    scanf("%d",&tst_case);
    printf("Enter the number of boxes:");
    for(int l=0;l<tst_case;l++)
    {
        scanf("%d",&num_box);
    }
    printf("Enter the number of candies in each box:");
    for(i=0;i<num_box;i++)
    {
        scanf("%ld",&c[i]);
    }
    for(i=0;i<num_box;i++)
    {
        for(j=i+1;j<num_box;j++) { if(c[i]>c[j])
            {
                temp=c[i];
                c[i]=c[j];
                c[j]=temp;
            }
        }
    }
    sum=0;
    k=0;
    for(i=0;i<num_box;i++)
    {
        sum=sum+c[i];
        s[k]=sum;
        k++;
    }
    times=0;
    printf("Minimum time requried:");
    for(i=1;i<k;i++)
    times=times+s[i];
    
    printf("%d\n",times);
    
    return 0;
}

Output: 

1
4
1 2 3 4
19

C++ PROGRAM 

#include<bits/stdc++.h>
using namespace std;

int main() 
{
    int i,j;
    int num_box=0,k=0,sum=0,times=0,tst_case,temp=0;
    long c[10000],s[10000];
    cout<<("Enter the number of test case:");
    cin>>tst_case;
    cout<<("Enter the number of boxes:");
    for(int l=0;l<tst_case;l++) { cin>>num_box;
    }
    cout<<("Enter the number of candies in each box:");
    for(i=0;i<num_box;i++) { cin>>c[i];
    }
    for(i=0;i<num_box;i++)
    {
        for(j=i+1;j<num_box;j++) { if(c[i]>c[j])
            {
                temp=c[i];
                c[i]=c[j];
                c[j]=temp;
            }
        }
    }
    sum=0;
    k=0;
    for(i=0;i<num_box;i++)
    {
        sum=sum+c[i];
        s[k]=sum;
        k++;
    }
    times=0;
    cout<<("Minimum time requried:");
    for(i=1;i<k;i++)
    times=times+s[i];
    
    cout<<times;
    
    return 0;
}

Otuput: 

1
4
1 2 3 4
19

JAVA PROGRAM

import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n, i, k = 0, sum = 0, s1 = 0, t, temp = 0, j;
        long c[] = new long[1000009];
        long s[] = new long[100009];
        System.out.println("Enter a no");
        t = sc.nextInt();
        for (int l = 0; l < t; l++)
        {
            n = sc.nextInt();
            for (i = 0; i < n; i++)
                c[i] = sc.nextLong();
            for (i = 0; i < n; i++) {
                for (j = i + 1; j < n; j++) { if (c[i] > c[j])
                    {
                        temp = (int) c[i];
                        c[i] = c[j];
                        c[j] = temp;
                    }
                }
            }
            sum = 0;
            k = 0;
            for (i = 0; i < n; i++)
            {
                sum = (int) (sum + c[i]);
                s[k] = sum;
                k++;
            }
            s1 = 0;
            for (i = 1; i < k; i++)
                s1 = (int) (s1 + s[i]);
            System.out.println(s1);
        }
    }

}

Output:

1
4
1 2 3 4

19

PYTHON PROGRAM 

T =  int(input())
arr = []
arr1 = []
for i in range(0, T):
    N = int(input())
    for i in range(0, N):
        arr.append(int(input()))
        arr.sort()
        count = arr[0]
    for i in range(1, len(arr)):
        count = count + arr[i]
        arr1.append(count)
print(sum(arr1))

Output: 

1
4
1 2 3 4
19

Question 3: Left Rotation

Problem Statement

A left rotation operation on an array shifts each of the array’s elements unit to the left. For example, if 2 left rotations are performed on array [1, 2, 3, 4, 5], then the array would become [3, 4, 5, 1, 2].

Given an array of integers and a number, , perform left rotations on the array. Return the updated array to be printed as a single line of space-separated integers.

Function Description

Complete the function rotLeft in the editor below. It should return the resulting array of integers.

rotLeft has the following parameter(s):

  • An array of integers .
  • An integer , the number of rotations.

Input Format

The first line contains two space-separated integers and , the size of and the number of left rotations you must perform.

The second line contains space-separated integers a[i].

Constraints

  • 1 <= n <= 10^5
  • 1 <= d <= n
  • 1 <= a[i] <= 10^8

Output Format

Print a single line of space-separated integers denoting the final state of the array after performing d left rotations.

Sample Input
5 4
1 2 3 4 5

Sample Output
5 1 2 3 4

Explanation
When we perform d=4 left rotations, the array undergoes the following sequence of changes:

[1,2,3,4,5] → [2,3,4,5,1] → [3,4,5,1,2] → [4,5,1,2,3] → [5,1,2,3,4]

Test Case : 1

Input (stdin)

  • 5 4
  • 1 2 3 4 5

Expected Output

  • 5 1 2 3 4

Test Case : 2
Input (stdin)

  • 20 10
  • 41 73 89 7 10 1 59 58 84 77 77 97 58 1 86 58 26 10 86 51

Expected Output

  • 77 97 58 1 86 58 26 10 86 51 41 73 89 7 10 1 59 58 84 77

C PROGRAM 

#include 
int rotLeft(int arr[], int n, int d)
{
    int i, j;
    int first;
    for(i=0; i<d; i++)
    {
        first = arr[0];
        for(j=0; j<n-1; j++)
        {
            arr[j] = arr[j+1];
        }
        arr[j] = first;
    }
    return *arr;
}
int main()
{
    int n, d, i;
    scanf("%d",&n);
    scanf("%d",&d);
    int list[n];
    for(i=0; i<n; i++)
    {
        scanf("%d",&list[i]);
    }
    rotLeft(list, n, d);
    for(i=0; i<n; i++)
    {
        printf("%d ",list[i]);
    }
}

C++ PROGRAM

#include<bits/stdc++.h>
using namespace std;
int rotLeft(int arr[], int n, int d)
{
    int i, j;
    int first;
    for(i=0; i<d; i++)
    {
        first = arr[0];
        for(j=0; j<n-1; j++) { arr[j] = arr[j+1]; } arr[j] = first; } return *arr; } int main() { int n, d, i; cin>>n;
    cin>>d;
    int list[n];
    for(i=0; i<n; i++) { cin>>list[i];
    }
    rotLeft(list, n, d);
    for(i=0; i<n; i++)
    {
        cout<<list[i]<<" ";
    }
}

JAVA PROGRAM 

import java.util.*;
class Main
{
    public static void rotateLeft(int a[],int n, int d)
    {
        int first,i,j;
        for(i=0;i<d;i++)
        {
            first=a[0];
            for(j=0;j<n-1;j++)
                a[j]=a[j+1];
            a[j]=first;
        }
    }
    public static void main(String[] args)
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int d=sc.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;i++)
            a[i]=sc.nextInt();
rotateLeft(a,n,d);

for(int i=0;i<n;i++)
System.out.print(a[i]+" ");
}
}

PYTHON PROGRAM 

def rotateLeft(n,d,arr):
    for i in range(d):
        arr = rotatearr(n,arr)
    return arr
    
def rotatearr(n, arr):
    first = arr[0]
    for i in range(n-1):
        arr[i] = arr[i+1]
    arr[n-1] = first
    return arr

, d = map(int, input().split())
arr = list(map(int, input().split()))
for i in rotateLeft(n,d,arr):
    print(i, end=" ")

Question 4: Vowel Encryption

Problem Statement  :

There is an encryption game going on. You will be given a number. If a digit is prime, it will take a vowel. Otherwise it will take a consonant value.
By this process, you have to make the string the lexicographically smallest possible. For a given number, print the output as a string.;

Input Format:
An integer n denoting the number.
Output Format:
The encrypted word.

Sample Input: 123421
Sample Output: baecab

C++ PROGRAM 

#include<bits/stdc++.h>

using namespace std;
map < char, char > M;
map < int, bool > prime;

int main() {
    prime[2] = true;
    prime[3] = true;
    prime[5] = true;
    prime[7] = true;
    char vow[] = {
        'a',
        'e',
        'i',
        'o',
        'u'
    };
    char con[] = {
        'b',
        'c',
        'd',
        'f',
        'g',
        'h'
    };
    int jv = 0, jc = 0;
    string s;
    cin >> s;
    for (auto i: s) {
        if (prime[i - '0']) {
            if (M[i]) {} else {
                M[i] = vow[jv];
                jv++;
            }
        } else if (M[i]) {} else {
            M[i] = con[jc];
            jc++;
        }
    }
    for (auto i: s) cout << M[i];
}

JAVA PROGRAM

import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String vowel = "aeiou";
        char arr[] = new char[10];
        arr[2] = 'a';
        arr[3] = 'e';
        arr[5] = 'i';
        arr[7] = 'o';
        char ch = 'b';
        for (int i = 1; i < arr.length; i++) {
            if (vowel.indexOf(ch) != -1) {
                ch++;
                continue;
            } else if (arr[i] == 0)
                arr[i] = (char) ch++;
        }
        int temp = n;
        int res = 0;
        while (temp != 0) {
            res = res * 10 + temp % 10;
            temp = temp / 10;
        }
        int i = 1;
        while (res != 0) {
            System.out.print(arr[res % 10]);
            res = res / 10;
        }
    }

}

PYTHON PROGRAM 

s = input()
res = []
x, y = 0, 0
v = "aeiou"
c = "bcdfgh"
p = "2357"
ans = sorted(set(s))
for i in ans:
    if i in p:
        res.append(v[x])
        x += 1
    else:
        res.append(c[y])
        y += 1
for i in s:
    print(res[ans.index(i)], end="")

Question 5: Class Monitor

Problem Statement :

After JEE Mains, some students got admission into an engineering college. Now there is a class consisting of such n students, and the HOD came to say it is time to select the class monitor. But He never gets all of them at one time. So he brought a register, every time he gets someone with less rank than the previous time he cut the name and wrote the name of the student and the rank.
For a given number of ranks he gets each time, you have to predict how many names are cut in the list.

Constraints:
Number of Visiting<=10^9
ranks <=10000

Input Format:
Number of Visiting N in their first line
N space separated ranks the HOD gets each time

Output Format:
Number of ranks cut in the list

Sample Input:
6
4 3 7 2 6 1

Sample Output:
3

C++ PROGRAM 
#include <bits/stdc++.h>

using namespace std;

int main() {
    int n, p, m = INT_MAX, ans = 0;
    cin >> n;
    vector < int > a(n);
    for (int i = 0; i < n; i++) { cin >> p;
        if (p < m) {
            m = p;
            ans++;
        }
    }
    cout << ans - 1;
}

JAVA PROGRAM 

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        int n, p, ans = 0, m = Integer.MAX_VALUE;
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            p = sc.nextInt();
            if (p < m) {
                m = p;
                ans++;
            }
        }
        System.out.print(ans - 1);
    }
}

PYTHON PROGRAM 

n = int(input())
a = list(map(int, input().split()))
m = a[0]
ans = 0
for i in range(1, n):
    if a[i] < m:
        m = a[i]
        ans += 1
print(ans)

While using this page to get an Amcat Coding Questions with Answers and AMCAT Coding Interview Questions. Kindly watch dailyrecruitment.in site.

INSTAGRAM LINK FOLLOW NOW >>
JOB ALERT ON TELEGRAM JOIN NOW>>

Govt Jobs by Qualifications

Education & Vacancies Salary Apply Link
10th Pass Govt Jobs - 5,000 Vacancies Rs. 5,200 - 63,200 Apply Now
12th Pass Govt Jobs - 18,000+ Vacancies Rs. 5,200 - 92,300 Apply Now
ITI Pass Jobs - 3,500 Vacancies Rs. 5,200 - 35,000 Apply Now
Any Graduate Jobs - 19,100 Vacancies Rs. 5,200 - 92,300 Apply Now
Central Govt Jobs Rs. 5,200 - 17,000 Apply Now
Bank Jobs - 1,000 Vacancies Rs. 5,200 - 29,200 Apply Now
Diploma Jobs - 9,300 Vacancies Rs. 5,200 - 35,000 Apply Now
BTech/BE Jobs - 18,000 Vacancies Rs. 15,000 - 1,00,000 Apply Now
Data Entry Jobs - 1,300 Vacancies Rs. 5,200 - 29,200 Apply Now
Private Jobs Rs. 10,000 - 67,700 Apply Now