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 position 1: locations[1] = 0, max((1 – 0),
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)); } }
Govt Jobs by Qualifications
Education & Vacancies | Salary | Apply Link |
---|---|---|
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 |