0% found this document useful (0 votes)
7 views6 pages

Part 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views6 pages

Part 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

DEBUG WITH SHUBHAM

Accenture Technical Assessment Detailed Overview

Coding Question

https://www.youtube.com/@DebugWithShubham

https://www.linkedin.com/in/debugwithshubham/

https://www.instagram.com/debugwithshubham/

https://topmate.io/debugwithshubham

https://t.me/debugwithshubham


Chocolate Distribution Problem
Given an array of N integers where each value represents the number of
chocolates in a packet. Each packet can have a variable number of chocolates.
There are m students, the task is to distribute chocolate packets such that:
•Each student gets one packet.
•The difference between the number of chocolates in the packet with
maximum chocolates and the packet with minimum chocolates given to the
students is minimum.

Input : arr[] = {7, 3, 2, 4, 9, 12, 56} , m = 3


Output: Minimum Difference is 2

Input : arr[] = {3, 4, 1, 9, 56, 7, 9, 12} , m = 5


Output: Minimum Difference is 6
C++ Python
JAVA
import java.util.Arrays;
#include <bits/stdc++.h> public class ChocolateDistribution {
using namespace std; public static int chocolateDistribution(int arr[], int m) {
int findMinDiff(int arr[], int n, int m) if (arr.length == 0 || m == 0) {
{ return 0;
if (m == 0 || n == 0) }
return 0; Arrays.sort(arr);
sort(arr, arr + n); if (arr.length - 1 < m) {
return -1;
if (n < m)
}
return -1; int min_diff = Integer.MAX_VALUE;
int min_diff = INT_MAX; for (int i = 0; i < arr.length; i++) {
for (int i = 0; i + m - 1 < n; i++) { int nextWindow = i + m - 1;
int diff = arr[i + m - 1] - arr[i]; if (nextWindow >= arr.length)
if (diff < min_diff) break;
min_diff = diff; int diff = arr[nextWindow] - arr[i];
} min_diff = Math.min(min_diff, diff);
return min_diff; }
return min_diff;
}
}
int main()
{ public static void main(String[] args) {
int arr[] = { 12, 4, 7, 9, 2, 23, 25, 41, 30, int arr[] = {12, 4, 7, 9, 2, 23, 25, 41, 30, 40, 28, 42, 30, 44, 48, 43, 50};
40, 28, 42, 30, 44, 48, 43, 50 }; int m = 7;
int m = 7; int result = chocolateDistribution(arr, m);
int n = sizeof(arr) / sizeof(arr[0]); if (result != -1) {
cout << "Minimum difference is " System.out.println("Minimum difference is " + result);
<< findMinDiff(arr, n, m); } else {
return 0; System.out.println("Invalid input");
}
}
}
}
Given two strings s1 and s2 consisting of lowercase characters, the task is to check whether the two
given strings are anagrams of each other or not. An anagram of a string is another string that contains
the same characters, only the order of characters can be different. For example, “act” and “tac” are
anagrams of each other.
Input:
Input 1: 1st string
Input 2: 2nd string
Output:
(If they are anagrams, the function will return ‘yes’. Otherwise, it will return ‘no’.)
Example
Input 1: listen -

Input 2: silent
Output:
Yes
Explanation
Listen and Silent are anagrams (an anagram is a word formed by rearranging the letters of the other word).
C++ JAVA

#include <algorithm> import java.util.Arrays;


#include <iostream> Python
public class AnagramChecker {
using namespace std; public static boolean areAnagrams(String s1, String s2)
{
bool areAnagrams(string s1, string s2) char[] charArray1 = s1.toCharArray();
{ char[] charArray2 = s2.toCharArray();
sort(s1.begin(), s1.end()); Arrays.sort(charArray1);
Arrays.sort(charArray2);
sort(s2.begin(), s2.end()); return Arrays.equals(charArray1, charArray2);
return s1 == s2; }
}
public static void main(String[] args)
{
int main() String str1 = "abcd";
String str2 = "adce";
{
string str1 = "abcd"; if (areAnagrams(str1, str2)) {
string str2 = "adce"; System.out.println("True");
}
else {
if (areAnagrams(str1, str2)) { System.out.println("False");
cout << "True" << endl; }
} }
else { }
cout << "False" << endl;
}

return 0;
}

You might also like