Samsung Coding Questions and Answers
Samsung Coding Questions with Solutions
Samsung Coding Questions and Answers is a most searched topic by the freshers who are preparing for Samsung’s Placement Assessments. Here you will find Samsung Coding Questions and Answers, asked in Technical Interviews during the Hiring Process of the company along with Job Profile, CTC Offered, and Job location.
About Samsung
Samsung Electronics is a South Korean Company that is the largest producer of Electronic Devices. This company also have a Research Division in various countries, called Samsung Research, an Advanced facility for the R&D purpose of different products manufactured by the company.
This part of the company mainly focuses on the advancement of the vast range of Technical Areas like AI & Robotics, Security & Privacy and its most common manufacturing unit called Samsung Electronics.
About Samsung Recruitment Process
This Hiring process consists of following steps :
- Written Test [ MCQs Based ]
- Technical Test
- Technical and HR Interview
Details of Samsung Recruitment Exam :
Samsung | Number of Questions | Time |
---|---|---|
Aptitude Test | 25 Questions | 45 Minutes |
Technical Test | 2 – 3 Questions | ~ 60 – 90 Minutes |
For more details on Samsung Recruitment Process, we have given all the necessary details in the following Tabular Form
Samsung | Related Information |
---|---|
Position : | Software Engineer Intern |
Course : |
|
Eligibility Criteria / Academic Qualification Required : | Minimum 75 % required throughout 10th, 12th, and Graduation. |
Cost to Company (CTC) |
|
Selection Process : |
|
Joining Location : | Noida |
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Samsung Coding Questions
Question 1: Hostel warden
Problem Statement :
There is a hostel warden in some XYZ hostel. He is very strict with students. He has some set of rules to allow students to let them out.
Students are in random order but warden don’t allow them in that way.
Rule 1- whose initial is a prime value should go out before whose initial is a composite value.
Rule 2- if two students have prime value , a student with less value goes out first
Rule 3- if two students have composite value , a student with greater value goes out first
NOTE:- consider the ASCII value of the initial to find it is prime or composite.
Input format:
The first line of input contains the number of students N
The second line of input contains random order of the students S.
(students at index zero goes out first and students at index N-1 goes last)
Constraints
1<=number of students <=105
33<=ASCII Of Characters<=126
Output Format
The single line of output should contain the required modified order of students to go out.
Sample Input
13
Kkunjkhahorin
Sample Output
akkuronnjihhK
Explanation
For primes: a<k
For Composite: K<h<i<j<n<o<r<u
Adding up logic, the required answer is akkuronnjihhK
#include <bits/stdc++.h> using namespace std; int main() { int n;cin>>n; string s;cin>>s; int prime[128]; prime[0]=prime[1]=0; int p=2; for(int i=2;i<128;i++) prime[i]=1; while(p*p<=127) { if(prime[p]) { for(int i=p*p;i<=127;i+=p) prime[i]=0; } p++; } string s1,s2; for(auto i:s) { if(prime[i]) s1+=i; else s2+=i; } sort(s1.begin(),s1.end()); sort(s2.begin(),s2.end()); reverse(s2.begin(),s2.end()); cout<< s1<< s2; }
import java.util.Collections; import java.util.Scanner; import java.util.Vector; public class Applicartion22 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String s = sc.next(); boolean primes[] = new boolean[127]; for (int i = 0; i < 127; i++) { primes[i] = true; } primes[0] = false; primes[1] = false; int p = 2; while (p * p <= 126) { if (primes[p]) { for (int i = p * p; i < 127; i += p) { primes[i] = false; } } p += 1; } Vector < Character > s1 = new Vector < > (); Vector < Character > s2 = new Vector < > (); for (int i = 0; i < s.length(); i++) { char ch = s.charAt(i); if (primes[(int) ch]) { s1.add(ch); } else { s2.add(ch); } } Collections.sort(s1); Collections.sort(s2); for (int i = 0; i < s1.size(); i++) { System.out.print(s1.get(i)); } for (int i = s2.size() - 1; i >= 0; i--) { System.out.print(s2.get(i)); } } }
n = int(input()) s = input() prime = [True] * 127 prime[0] = prime[1] = False p = 2 while p * p <= 126: if prime[p]: for i in range(p * p, 127, p): prime[i] = False p += 1 s1 = [] s2 = [] for i in s: if prime[ord(i)]: s1.append(i) else: s2.append(i) s1.sort() s2.sort(reverse=True) s1.extend(s2) print("".join(s1))
Question 2 : Jagannath and his Brothers
Problem Statement :
Jagannath was with two of his young brothers in work. He wants to work less, and wants his brothers to work more, as he is a lazy person. Now, in the work field, there is an array of buildings, from where they can earn money. So that there arises no conflict between his brothers that who earns more, he arrives in one building, tells his brother that the very building will bring the most money (Which may not be true), and tells one of his brothers to go to the left and another one to go to the right.
You have to write a program so that you can predict which building will be getting Jagannath, and how much money each of his friends are gonna earn.
Input Format:
First line saying the number of test cases, n.
Then next n pairs of lines, first one depicting the number of buildings k and second one containing k space separated integers denoting the number of earnings possible.
Constraints
1 <= n <= 10 ^ 6
1 <= k < n
-10 ^ 9 <= a[i] <= 10 ^ 9 (Earnings)
1 <= t <= 25
Output Format:
n lines, with the index of building jagannath working, space separately the money His brothers each making. If the combination is not possible, answers are 0.
Sample Input:
1
5
1 2 2 4 5
Sample Output:
4 5
Explanation:
Jagannath will work in the 4th building, and his brothers are making 5 rupees each.
#include <bits/stdc++.h> using namespace std; void func() { int k; cin >> k; int ans1 = 0, ans2 = 0; vector < int > a(k), l(k), r(k); for (int i = 0; i < k; i++) cin >> a[i]; l[0] = a[0]; r[k - 1] = a[k - 1]; for (int i = 1; i < k; i++) l[i] = l[i - 1] + a[i]; for (int i = k - 2; i >= 0; i--) r[i] = r[i + 1] + a[i]; for (int i = 1; i < k - 1; i++) if (l[i - 1] == r[i + 1]) { ans1 = i + 1; ans2 = l[i - 1]; break; } cout << ans1 << " " << ans2 << endl; } int main() { int n; cin >> n; while (n--) func(); }
import java.util.Scanner; import java.util.Vector; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for (int z = 0; z < t; z++) { int k = sc.nextInt(); int ans1 = 0, ans2 = 0; int[] a = new int[k]; int[] l = new int[k]; int[] r = new int[k]; for (int i = 0; i < k; i++) { a[i] = sc.nextInt(); } l[0] = a[0]; r[k - 1] = a[k - 1]; for (int i = 1; i < k; i++) l[i] = l[i - 1] + a[i]; for (int i = k - 2; i >= 0; i--) r[i] = r[i + 1] + a[i]; for (int i = 1; i < k - 1; i++) { if (l[i - 1] == r[i + 1]) { ans1 = i + 1; ans2 = l[i - 1]; break; } } System.out.println(ans1 + " " + ans2); } } }
for t in range(int(input())): n = int(input()) ar = list(map(int, input().split())) left, right = [0] * n, [0] * n left[0] = ar[0] right[-1] = ar[-1] for i in range(1, n): left[i] = left[i - 1] + ar[i] for i in range(n - 2, -1, -1): right[i] = right[i + 1] + ar[i] i, j, m, y = 0, 2, 0, 0 while i < n and j < n: if left[i] == right[j]: m = left[i] y = i + 2 break i += 1 j += 1 print(y, m)
Question 3 : Simple problem
Problem Statement :
Mr X is a teacher of maths. He came across a very simple problem. In the problem you have to arrange the numbers in an ascending order and calculate the total number of swaps required. The number of swaps must be minimum. But Mr X is busy with some other tasks and you being his favourite student , so he asks you to solve this problem.
Constraints:
1<=T<=100
1<=N<=100
1<=A[ ] <=1000
Examples
Input :
4
4 3 1 2
Output:
2
Explanation: Swap index 0 with 3 and 1 with 2 to form the sorted array {1, 2, 3, 4}.
Input :
5
1 5 4 3 2
Output :
2
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector < int > arr(n); for (int i = 0; i < n; i++) cin >> arr[i]; vector < pair < int, int >> ap(n); for (int i = 0; i < n; i++) { ap[i].first = arr[i]; ap[i].second = i; } sort(ap.begin(), ap.end()); vector < bool > v(n, false); int ans = 0; for (int i = 0; i < n; i++) { if (v[i] || ap[i].second == 1) continue; int cs = 0, j = i; while (!v[j]) { v[j] = 1; j = ap[j].second; cs++; } if (cs > 0) ans += cs - 1; } cout << ans; }
import java.util.Scanner; public class Main { static int minimumSwaps(int[] arr) { int count = 0; int i = 0; while (i < arr.length) { if (arr[i] != i + 1) { while (arr[i] != i + 1) { int temp = 0; temp = arr[arr[i] - 1]; arr[arr[i] - 1] = arr[i]; arr[i] = temp; count++; } } i++; } return count; } public static void main(String[] args) { Scanner ss = new Scanner(System.in); int n = ss.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = ss.nextInt(); } System.out.println(minimumSwaps(arr)); } }
n = int(input()) ar = list(map(int, input().split())) arrpos = list(enumerate(ar)) arrpos.sort(key=lambda it: it[1]) vis = {k: False for k in range(n)} ans = 0 for i in range(n): if vis[i] or arrpos[i][0] == i: continue j = i cycles = 0 while vis[j] == False: vis[j] = True cycles += 1 j = arrpos[j][0] if cycles > 0: ans += cycles - 1 print(ans)
Question 4: Shushil’s Madness
Problem Statement :
Shushil has gone crazy after he lost a big amount of his money in the share market. Now he keeps all the money he has distributed in his room and calculates them in a very problematic way. Every time he calculates hisnetworth, he writes it down adding with the last 3 rooms he has one.
Then after that when he reaches the next room he adds the last 3 rooms’s money with the money found in that room and adds again. Suppose he is in ith room, he will add i-1,i-2 and i-3th rooms money with ith one and add it into his net worth (if the rooms exist).
Given an array of money in the rooms, find what will he calculate as his net worth?
Input Format:
First line saying the number of rooms, r
Next line r space separated money amounts in each room
Next line contains an m, denoting a number that we will use to take module of the final value
Constraints:
1<= r <= 1018
1<= a[i] <= min(600,r)
1<= M <= 1018
Output Format:
Print the answer on the first line
Sample Input:
5
1 2 3 4 5
100
Sample Output:
34
#include <bits/stdc++.h> using namespace std; int main() { int m, r, ans = 0; cin >> r; vector < int > a(r); for (int i = 0; i < r; i++) cin >> a[i]; cin >> m; for (int i = 0; i < 4; i++) for (int j = 0; j <= i; j++) ans += a[j]; for (int i = 4; i < r; i++) ans += (a[i] + a[i - 1] + a[i - 2] + a[i - 3]); cout << ans % m; }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int m, r, ans = 0; r = sc.nextInt(); int[] a = new int[r]; for (int i = 0; i < r; i++) a[i] = sc.nextInt(); m = sc.nextInt(); for (int i = 0; i < 4; i++) for (int j = 0; j <= i; j++) ans += a[j]; for (int i = 4; i < r; i++) ans += (a[i] + a[i - 1] + a[i - 2] + a[i - 3]); System.out.println(ans % m); } }
ans = 0 r = int(input()) a = list(map(int, input().split())) m = int(input()) for i in range(4): for j in range(i + 1): ans += a[j] for i in range(4, r): ans += a[i] + a[i - 1] + a[i - 2] + a[i - 3] print(ans % m)
Question 5: Strange rule
Problem Statement :
There are two friends Ram and Shyam. They saw each other after a very long time. Then they remember the rule they make when they are of very small age. They have decided that whenever they see each other they will move towards each other in a very dramatic way.
Let’s say Ram and Shyam are ‘D’ meters apart.
Ram moves 1 meter in each step he takes but Shyam moves are increases linearly starting from 1, i.e., he moves 1 meter in his first step then 2 meters on the second, 3 meters on the third step and so on till he cannot take a step.
Assume they both take steps simultaneously till shyam is able to make a step. Whenever shyam can’t make a step, he waits patiently at that place and the rest of the distance is covered by Ram.
Calculate the minimum number of steps they take in total before meeting each other.
Your task is to output the minimum number of total steps required before Ram and Shyam can meet each other.
Input Format:
The first line contains the number of test cases ‘T’.
The next ‘T’ line contains the distance ‘D’.
Constraints:
1 T 105
1 D 105
Output Format:
Output ‘T’ lines with each line containing a single integer denoting the minimum number of jumps they take before hugging each other for each test case.
Sample Input
1
3
Sample Output
3
Explanation
Let Ram be at position 0 of x-axis and Shyam be at position 3 of the x-axis.
Ram jumps to position 1 and simultaneously Shyam jumps to position 2.
Now Shyam can’t make a jump because if he does so, then he will be jumping over Ram which is undesirable. So she patiently waits at position 2.
Finally, Ram jumps to position 2 and they hug each other
You can clearly see 3 jumps are required. Two by Ram and One by Shyam.
So the output is 3.
Sample Input
1
5
Sample Output
4
#include <bits/stdc++.h> using namespace std; int main() { int a, d, t; cin >> t; while (t--) { cin >> d; int cnt = 0, t = 1, j = 1, tp = 0, jp = d; while (d > 0) { if (t + j > d) { d -= t; tp += t; cnt += 1; } else if (t + j == d) { if (tp + t == jp - j) { cnt += 2; d -= (t + j); jp -= j; tp += t; } else { d -= t; tp += t; cnt++; } } else { d -= (t + j); tp += t; jp -= t; j++; cnt += 2; } } cout << cnt << endl; } }
import java.util.*; import java.io.*; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for (int i = 0; i < n; i++) { int d = sc.nextInt(); int cnt = 0; int t = 1; int j = 1; int tp = 0; int jp = d; while (d > 0) { if (t + j > d) { d = d - t; tp += t; cnt += 1; } else { if (t + j == d) { if (tp + t == jp - j) { cnt += 2; d = d - t - j; jp -= j; tp += t; } else { d = d - t; tp += t; cnt += 1; } } else { d = d - t - j; tp += t; jp -= j; j += 1; cnt += 2; } } } System.out.println(cnt); } } }
for t in range(int(input())): d = int(input()) cnt, t, j, tp, jp = 0, 1, 1, 0, d while d > 0: if t + j > d: d = d - t tp += t cnt += 1 elif t + j == d: if tp + t == jp - j: cnt += 2 d = d - t - j jp -= j tp += t else: d = d - t tp += t cnt += 1 else: d = d - t - j tp += t jp -= j j += 1 cnt += 2 print(cnt)
FAQs related to Samsung Coding Questions
Question 1: Does Samsung asks coding questions in there Recruitment Process?
Yes, Samsung always asks Coding Questions in there Technical Test and Technical Interview for Hiring the suitable candidates.
Question 2: What kind of roles are available at Samsung in India?
Samsung offers various Job profiles in the field of industry electronics, including appliances, digital media devices, semiconductors, memory chips, and integrated systems as Software Engineer, UI – UX Designer, System Engineer, etc.
Question 3: What is the recruitment process at Samsung India?
The recruitment process at Samsung India typically involves multiple stages, including Global Samsung Aptitude Test, technical assessments, technical interviews and HR Interview. The specific process may vary depending on the role and location.
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
Login/Signup to comment