Thanks to visit codestin.com
Credit goes to www.scribd.com

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

14-Sep-2024 Capgemini Coding Question

Uploaded by

sabeb28630
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)
48 views6 pages

14-Sep-2024 Capgemini Coding Question

Uploaded by

sabeb28630
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

14-SEP-2024 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
Question -1
C++ Java
#include <iostream> import java.util.ArrayList;
import java.util.List;
#include <vector>
#include <string> Python public class SnakeWaterGun {
int main() { public static void main(String[] args) {
std::string s = "watergunwaterwatergunwater"; String s = "watergunwaterwatergunwater";
std::vector<std::string> delimiters = {"water", "gun", "snake"}; s = "watergunwaterwatergunwater" String[] d = {"water", "gun", "snake"};
std::vector<std::string> ans; print(cnter','gun','snake'] int cnt = 0;
int cnt = 0; List<String> ans = new ArrayList<>();
cnt = 0 while (!s.isEmpty()) {
while (!s.empty()) {
ans = [] for (String move : d) {
for (const std::string& move : delimiters) {
if (s.find(move) == 0) { while s: if (s.startsWith(move)) {
ans.push_back(move); for i in d: ans.add(move);
s = s.substr(move.length()); if s.startswith(i): s = s.substring(move.length());
break; ans.append(i) break;
} s = s[len(i):] }
} }
break
} }
n = len(ans)
int n = ans.size();
for i in range(0,n,2): int n = ans.size();
for (int i = 0; i < n; i += 2) { if ans[i] == 'snake' and ans[i+1] == 'water': for (int i = 0; i < n; i += 2) {
std::string playerA = ans[i]; cnt +=1 String playerA = ans.get(i);
std::string playerB = ans[i + 1]; elif ans[i] == 'water' and ans[i+1] == 'gun': String playerB = ans.get(i + 1);
cnt +=1
if (playerA == "snake" && playerB == "water") { if (playerA.equals("snake") && playerB.equals("water")) {
elif ans[i] == 'gun' and ans[i+1] == 'snake':
cnt++; cnt++;
cnt +=1 } else if (playerA.equals("water") && playerB.equals("gun")) {
} else if (playerA == "water" && playerB == "gun") {
cnt++;
print(cnt) cnt++;
} else if (playerA == "gun" && playerB == "snake") { } else if (playerA.equals("gun") && playerB.equals("snake")) {
cnt++; cnt++;
} }
} }
std::cout << cnt << std::endl; System.out.println(cnt);
}
return 0; }
}
Question-2
Python Java
import java.lang.Math;
import math
def minimum_power_greedy(P, X, Y):
public class MinimumPower {
use_big_machines = P // 100
remaining_customers = P % 100
public static int minimumPowerGreedy(int P, int X, int Y) {
power_M = use_big_machines * X
int useBigMachines = P / 100;
power_M_remaining = X #40
int remainingCustomers = P % 100;
power_N_remaining = math.ceil(remaining_customers / 4) * Y # 24
total_power_use_big_machine = power_M + power_M_remaining
int powerM = useBigMachines * X;
total_power_use_small_machine = power_M + power_N_remaining
int powerMRemaining = X;
return min(total_power_use_big_machine, total_power_use_small_machine)
int powerNRemaining = (int) Math.ceil(remainingCustomers / 4.0) * Y;
P=9
X = 40
int totalPowerUseBigMachine = powerM + powerMRemaining;
Y=8
int totalPowerUseSmallMachine = powerM + powerNRemaining;
print(minimum_power_greedy(P, X, Y))
return Math.min(totalPowerUseBigMachine,
totalPowerUseSmallMachine);
}

C++ public static void main(String[] args) {


int P = 9;
int X = 40;
int Y = 8;
#include <iostream> System.out.println(minimumPowerGreedy(P, X, Y));
#include <cmath> // For ceil() }
}
using namespace std;

int minimumPowerGreedy(int P, int X, int Y) {


int useBigMachines = P / 100;
int remainingCustomers = P % 100;
int powerM = useBigMachines * X;
int powerMRemaining = X;
int powerNRemaining = ceil(remainingCustomers / 4.0) * Y;

int totalPowerUseBigMachine = powerM + powerMRemaining;


int totalPowerUseSmallMachine = powerM + powerNRemaining;

return min(totalPowerUseBigMachine, totalPowerUseSmallMachine);


}

int main() {
int P = 9;
int X = 40;
int Y = 8;
cout << minimumPowerGreedy(P, X, Y) << endl;
return 0;
}

You might also like