Amazon Hackon Coding Round Questions & Answers 2024 | Amazon HackOn Hiring Challenge Questions 2024 | Amazon HackOn Hiring Challenge Coding Questions | Amazon HackOn Hiring Challenge Coding Questions For Freshers
Amazon Hackon Coding Round Questions & Answers 2024: Applicants with less than two years of experience are eligible to apply for the Amazon HackOn with Coding Challenge 2024. In order to apply for this Amazon Hackon coding competition, candidates must be highly motivated and creative thinkers with a Bachelor’s or Master’s degree in computer science, computer engineering, or a similar field. Amazon is hiring through the HackOn with Amazon Coding Challenge Contest 2023, which offers fantastic prize money, for novices or enthusiasts with 02 years of expertise. Those who pass the test will be hired by Amazon as software development engineers.
In the below section, you may get the Amazon Hackon Coding Round Coding Questions and Answers/ Amazon Hackon Coding Coding Questions With Solutions. You must use your programming talents and choose a language you are comfortable with, such as C, C++, Java, or even Python, to complete the coding tasks. More details like Amazon Hackon Coding Round Questions and Answers, Amazon Hackon Coding Questions and Answers, Amazon Hackon Interview Questions and Answers, Amazon Hackon Cut Off, Salary, Hike, Increment, Annual Appraisal, etc. are available on this page
Amazon Hackon Coding Challenge 2024: Important Topics
The majority of the questions in the Amazon Coding Challenge are in the areas of data structures and algorithms.
You should anticipate queries about data structures centered around the following subjects:
- Stacks
- Arrays
- Linked lists
- Heaps
- Hash Sets
- Hash Maps
- Queues
- Trees
- Graphs
You should anticipate inquiries on algorithms pertaining to:
- Quicksort
- Merge Sort
- Dynamic Programming
- Divide and Conquer
- Depth-First Search
- Breadth-First Search
- Binary Search
Amazon Hackon Coding Challenges 2024: Problems Questions
- Write a program to count the vowels and consonants in a given string.
- Write a program to reverse words in a given sentence without using any library methods.
- Design a vending machine.
- Write a program to reverse a linked list in place.
- Following are the kinds of problems you can expect in an Amazon Hackon Coding Challenge:
- Given an array of integers and a key, determine if the sum of any two integers equals the key.
- Merge two sorted linked lists so that the resulting linked list is also sorted.
- Write a program to sort a linked list in Java.
- Write a program to print duplicate characters from a string.
- Implement a radix sort algorithm.
- Write a program to find duplicate numbers in an array if it contains multiple duplicates.
Amazon Hackon Coding Round Questions With Solutions
Q) Write a program to find out and display prime numbers from the given list of integers. The program will accept input in two lines. First-line contains a number indicating the total number of integers in the list and the second line contains integers separated by spaces.
Example 1
- Input: 5
4 6 9 3 7 - Output: 3 7
Example 2
- Input: 10
8 10 3 12 7 15 11 2 17 26 - Output: 3 7 11 2 17
C++ PROGRAM
#include<bits/stdc++.h> using namespace std; map<int,int> m; bool ifPrime(int a) { if(m[a]==2||m[a]==1) return m[a]-1; if((a&1)==0) {m[a]=1;return false;} for(int i=3;i<=sqrt(a);i+=2) if(a%i==0) {m[a]=1;return 0;} m[a]=2; return 1; } int main() { m[2]=2; int n,a;cin>>n; for(int i=0;i<n;i++) { cin>>a; if(ifPrime(a)) cout<<a<<" "; } }
Q) Write a program that receives a word A and some texts as input. You need to output the texts (without modifying them) in the ascending order of the number of occurrences of the word A in the texts. The input is as follows: an integer M(between 1 and 100, inclusive), followed by the word A in the next line, and some text in each of the M next lines.
Note: The texts and the word A contain only lowercase Latin letters (a,b,c…,z) and blank spaces (“ ”). The maximum size of the texts and the word A is 100 Characters. Every text has a different number of occurrences of the word A.
Note 2:you must print one text per line without modifying the texts.
Example 1
- Input: 2
Java
I hate java
Python is a good programming language - Output: Python is a good programming language
I hate java
Example 2
- Input: 3
python
I like to code in python
python is named after a show name monty python and not after the snake python
I think python is good i think python is important than php - Output: i like to code in python
i think python is good i think python is important than php
python is named after a show name monty python and not after the snake python
C++ PROGRAM
#include<bits/stdc++.h> using namespace std; string s; map<string,int> m2; bool cmp(pair<string, int>& a, pair<string, int>& b) { return a.second < b.second; } void sort(map<string, int>& M) { vector<pair<string, int> > A; for (auto& it : M) { A.push_back(it); } sort(A.begin(), A.end(), cmp); for (auto& it : A) { for(int i=0;i<m2[it.first];i++) cout << it.first <<endl; } } int count(string s1) { istringstream ss(s1); int c=0; while(ss) { string w; ss>>w; if(w==s) c++; } return c; } int main() { int n;getline(cin,s);n=stoi(s); getline(cin,s); transform(s.begin(),s.end(),s.begin(),::tolower); vector<string> v(n); vector<int> a(n); map<string,int> m; for(int i=0;i<n;i++) { getline(cin,v[i]); transform(v[i].begin(),v[i].end(),v[i].begin(),::tolower); m2[v[i]]++; m[v[i]]=count(v[i]); } sort(m); }
JAVA PROGRAM
import java.util.*; public class Main { static int countOccurences(String str, String word) { String a[] = str.split(" "); int count = 0; for (int i = 0; i < a.length; i++) { if (word.equals(a[i])) count++; } return count; } public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); sc.nextLine(); String word=sc.next(); //System.out.println(word); sc.nextLine(); String arr[]=new String[n]; for(int i=0;i<n;i++) { arr[i]=sc.nextLine(); //System.out.println(arr[i]); } TreeMap<Integer,String> map=new TreeMap<Integer,String>(); for(int i=0;i<n;i++) { map.put(countOccurences(arr[i],word),arr[i]); } Set s=map.entrySet(); Iterator itr=s.iterator(); while(itr.hasNext()) { Map.Entry m=(Map.Entry)itr.next(); System.out.println(m.getValue()); } } }
PYTHON PROGRAM
from collections import defaultdict d=defaultdict(int) d1=defaultdict(int) n=int(input()) s=input() s=s.lower() l=[] for i in range(n): L=list(map(str,input().split())) s1=' '.join(i for i in L) c=0 for j in L: if s==j: c+=1 l.append(s1) d[i]=c d1[i]+=1 c=0 d=sorted(d.items(),key=lambda a:a[1]) for i in d: for j in range(d1[i[0]]): print(l[i[0]])
Q) Write a program that will print the sum of diagonal elements of a 10X10 matrix. The program will take a total of 100 numbers as input (10 numbers will be input per line and each number will be separated by a space).
Example 1
- Input: 1 2 3 4 5 6 7 8 9 0
0 1 2 3 4 5 6 7 8 0
3 4 5 6 7 8 9 6 4 0
2 3 4 5 6 7 8 9 3 2
3 4 5 6 7 4 3 2 1 3
3 4 5 6 2 4 4 2 4 6
2 3 4 6 2 4 6 2 3 5
2 3 5 6 2 4 6 2 3 5
2 4 6 2 1 4 3 3 5 2
3 3 5 2 4 6 2 1 4 6 - Output: 42
Example 2
- Input: 1 22 33 44 55 66 77 88 99 100
100 1 88 77 66 55 44 33 22 11
88 88 1 66 55 44 33 22 11 100
88 77 66 1 44 33 22 11 100 99
77 66 55 44 1 22 11 88 99 100
66 55 44 33 22 1 77 88 99 100
44 33 22 11 100 99 1 77 66 55
33 22 11 100 99 88 77 1 55 44
22 11 100 99 88 77 66 55 1 33
100 11 22 33 44 55 99 88 77 1 - Output: 10
C++ PROGRAM
C++ PROGRAM
#include<bits/stdc++.h> using namespace std;int main() { string s; int c=0; getline(cin,s); for (auto i:s) { if(i=='(') c++; if(i==')') c--; } cout<<(c==0); }
PYTHON PROGRAM
s=input() c=0 for i in s: if i =='(': c+=1 elif (i==')') and c>0 : c-=1 print(int(c>0))
Amazon HackOn Hiring Challenge Coding Questions & Answers 2024
Q): While playing an RPG game, you were assigned to complete one of the hardest quests in this game. There are n monsters you’ll need to defeat in this quest. Each monster i is described with two integer numbers – poweri and bonusi. To defeat this monster, you’ll need at least poweri experience points. If you try fighting this monster without having enough experience points, you lose immediately. You will also gain bonusi experience points if you defeat this monster. You can defeat monsters in any order.
The quest turned out to be very hard – you try to defeat the monsters but keep losing repeatedly. Your friend told you that this quest is impossible to complete. Knowing that, you’re interested, what is the maximum possible number of monsters you can defeat?
Input:
- The first line contains an integer, n, denoting the number of monsters. The next line contains an integer, e, denoting your initial experience.
- Each line i of the n subsequent lines (where 0 ≤ i < n) contains an integer, poweri, which represents power of the corresponding monster.
- Each line i of the n subsequent lines (where 0 ≤ i < n) contains an integer, bonusi, which represents bonus for defeating the corresponding monster.
Output
- 2
Example Programs:
JAVA PROGRAM
import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(); int exp = s.nextInt(); int monst[] = new int[n]; int bonus[] = new int[n]; for (int i = 0; i < n; i++) { monst[i] = s.nextInt(); } for (int i = 0; i < n; i++) { bonus[i] = s.nextInt(); } class Monster { private final int power, bonus; public Monster(int power, int bonus){ this.power = power; this.bonus = bonus; } } Monster[] monsters = new Monster[n]; for(int i = 0; i < n; i++) monsters[i] = new Monster(monst[i], bonus[i]); Arrays.sort(monsters, Comparator.comparingInt(m -> m.power)); int count = 0; for(Monster m: monsters){ if(exp < m.power) break; exp += m.bonus; ++count; } System.out.println(count); } }
n = int(input()) lev = int(input()) p = [] b = [] a = [] ans = 0 for i in range(n): p.append(int(input())) for j in range(n): b.append(int(input())) for k in range(n): a.append([p[k], b[k]]) a.sort() for z in a: if z[0] > lev: break lev += z[1] ans += 1 print(ans)
Q) Henry is extremely keen on history and every one of the ages of his family. He does a ton of exploration and understands that he has plummeted from the incomparable Amaya line. After a ton of looking through old records and the most recent records of the general public, he can discover all the parent-kid connections in his family right from the extraordinary ruler Ming of the tradition to himself.
These connections are given in the structure of a direct exhibit where the emperor is at the main position and his kids are at pos (2i + 1) and (2i + 2)
This is the pattern followed throughout.
Henry needs to sort out every one of the kin of individual X from the information.
Write a program for Henry to figure out all the siblings of person X from the data.
Return the sorted list of all of Henry’s siblings.
If no sibling return {-1}
- input 1: N, the length of the array
- input2: An array representing the ancestral tree
- input 3: X, the person whose siblings are sought.
- output – return the array of all siblings in increasingly sorted order.
Example 1 :
input 1: 5
input 2: {1,2,3,4,5}
input 3: 1
output: {-1}
Explanation: x is the root of the tree and has no siblings
Example 2 :
input 1: 6
input 2: {1,2,3,4,5,6}
input 3: 5
output: {4,6}
Explanation: {2,3 } are the children of {1}. {4,5,6 } are the children of {2,3}, thus the siblings of x= 5 are {4,6}
JAVA PROGRAM
import java.util.*; public class Main { Node root; static class Node { int data; Node left, right; Node (int data) { this.data = data; this.left = null; this.right = null; } } public static void main (String[]args) { Main t2 = new Main (); Scanner sc = new Scanner (System.in); int length = sc.nextInt (); int arr[] = new int[length]; for (int i = 0; i < length; i++) { arr[i] = sc.nextInt (); } int target = sc.nextInt (); t2.root = t2.insertLevelOrder (arr, t2.root, 0); Set < Integer > sets = t2.levelOrderBottom (t2.root, target); sets.remove (target); System.out.println (sets); } public static Node insertLevelOrder (int[]arr, Node root, int i) { if (i < arr.length) { Node temp = new Node (arr[i]); root = temp; root.left = insertLevelOrder (arr, root.left, 2 * i + 1); root.right = insertLevelOrder (arr, root.right, 2 * i + 2); } return root; } public Set < Integer > levelOrderBottom (Node root, int target) { if (root == null) { return null; } Queue < Node > q = new LinkedList <> (); q.offer (root); while (!q.isEmpty ()) { int qsize = q.size (); Set < Integer > temp = new HashSet <> (); for (int i = 0; i < qsize; i++) { Node child = q.poll (); temp.add (child.data); if (child.left != null) { q.offer (child.left); } if (child.right != null) { q.offer (child.right); } } if (temp.contains (target)) return temp; } return null; } }
PYTHON PROGRAM
def identify_siblings(tree_array, x): tree_len = len(tree_array) index = tree_array.index(x) level = 0 start_index = level number_of_nodes = 0 while start_index < tree_len: end_index = pow(2, level) + start_index if x in tree_array[start_index:end_index]: break level += 1 start_index = (2 * start_index) + 1 final_array = tree_array[start_index:end_index] final_array.remove(x) return final_array if final_array else [-1] n = int(input()) arr = [] for i in range(n): arr.append(int(input())) x = int(input()) print(identify_siblings(arr, x))
#include<bits/stdc++.h> using namespace std; int main() { int N, ans, price; cin>>N; int arr[N]; for (int i = 0; i < N; i++) cin>>arr[i]; price = 0; ans = 0; for (int i = 0; i < N; i++) { price = price + arr[i]; if (ans > price) { ans = price; } } cout << ans; }
C PROGRAM:
#include<stdio.h> int main() { int N, ans, price; scanf("%d", &N); int arr[N]; for (int i = 0; i < N; i++) scanf("%d", &arr[i]); price = 0; ans = 0; for (int i = 0; i < N; i++) { price = price + arr[i]; if (ans > price) { ans = price; } } printf("%d", ans); }
PYTHON PROGRAM
n = int(input()) arr = [] for i in range(n): arr.append(int(input())) min = 0 for i in range(1, n): if sum(arr[:i]) < min: min = sum(arr[:i]) print(min)
Amazon HackOn Hiring Challenge Coding Questions with Solutions For Freshers
Question: Amusement Park
Problem Statement: Aashay loves to go to WONDERLA , an amusement park. They are offering students who can code well with some discount. Our task is to reduce the cost of the ticket as low as possible.
They will give some k turns to remove the cost of one ticket where the cost of tickets are combined and given as string. Help Aashay in coding as he is not good in programming and get a 50% discount for your ticket.
Constraints:
- 1 <= number of tickets <= 10^5
- 1 <= K <= number of tickets
Input Format for Custom Testing:
- The first line contains a string,Tickets, denoting the given cost of each ticket.
- The next line contains an integer, K, denoting the number of tickets that is to be removed.
Sample Cases:
- Sample Input 1
203
3 - Sample Output 1
0
C++ PROGRAM
#include <iostream> #include <bits/stdc++.h> using namespace std; int smallestNumber (string num, int k) { if(num.length()<=k) return 0; unordered_map<char,int> pos; for(int i=0;i<num.length();i++) { pos[num[i]]=i;} string temp=num; sort(num.begin(),num.end()); string ans=num.substr(0,num.length()-k); vector<int> v; for(int i=0;i<ans.length();i++) v.push_back(pos[ans[i]]); sort(v.begin(),v.end()); string ret; for(int i=0;i<v.size();i++) {ret+=temp[v[i]];} int final=stoi(ret); return final; } int main() { string s; cin >> s; int k; cin >> k; int ans; cout<<smallestNumber(s,k)%(int)(pow(10,9)+7); return 0; }
PYTHON PROGRAM
import sys n=input() k=int(input()) n1=len(n) if len(n)<=k: print(0) sys.exit() a='' i=0 while i<(n1-1) and k>0: if int(n[i])>int(n[i+1]): i+=1 k-=1 continue else: a+=n[i] i+=1 a+=n[i] i+=1 if k>0: a=a[:-k] if i<=(n1-1): while i<n1: a+=n[i] i+=1 print(int(a)%((10**9)+7))
JOB ALERT ON INSTAGRAM | FOLLOW NOW>> |
JOB ALERT ON TELEGRAM | JOIN NOW>> |
Follow regularly our Dailyrecruitment.in site to get upcoming all up-to-date information.
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 |