**Accenture Hack Diva Coding Questions & Answers 2024 | Accenture Hack Diva Coding Questions For Engineering | Accenture Hack Diva Coding Questions For Graduates | Accenture Hack Diva Hackathon Coding Questions **

**Accenture Hack Diva Coding Questions & Answers 2024: **Coding is one of the most important components of the Accenture Hack Diva hiring procedure. This section will assess your problem-solving and programming efficiency. This round will consist of four code questions covering a variety of topics. You can supply the solutions in any of the supported programming languages. However, we suggest that you focus more on SQL, C++, Java, Python, & Others

Users are given a series of Accenture Hack Diva coding problems to test their cognitive and coding abilities. The level of the Accenture Hack Diva **Coding Questions** ranges from easy to moderate. More details like Accenture Hack Diva Java Coding Questions and Answers, Accenture Hack Diva Python Coding Questions and Answers, Accenture Hack Diva Coding Questions and Answers, Accenture Hack Diva Cut Off, Salary, Hike, Increment, Annual Appraisal, etc. are available on this page

**Accenture Hack Diva Hackathon Coding Questions With Solutions**

Organization Name | Accenture Hack Diva Hackathon |

Eligibile Qualification | B.E/B.Tech, M.E/M.Tech, MCA, and M.SC (Only CS and IT) |

Batch | 2023 |

Experience | Freshers |

Category | Coding Questions |

Official Website | https://indiacampus.accenture.com/events/hackdiva/ |

**Accenture Hack Diva Coding Questions **

- Execute this function: Int OperationsBinarystring(char* str)
- Execute this function: Def Autocount(x)
- Adam decides to do some charity work. From day 1 till day x, he will give i^2 coins to charity. On day ‘i’ (1 < = i < = x), find the number of coins he gives to charity.
- Find the sum of the divisors for the N integer number.
- Write a program that accepts the integer array of length ‘size’ and finds the largest number that can be formed by permutation.
- Form an array of 1000 integers and find out the second-largest number. If there is no second-largest number, return the value to –1.
- Execute this function: def differenceofSum(n.m)
- Execute this function: Int Numberofcarry(Integer num 1, Integer num 2)
- Execute this function: def LargeSmallSum(arr)
- Execute this function: def Productsmallpair(sum,arr)

**Accenture Hack Diva Coding Questions and Answers 2024**

**Questions:** 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); } }

**Questions: **One of the first lessons IT students learn is the representation of natural numbers in the binary number system (base 2) This system uses only two digits, 0 and 1. In everyday life we use for convenience the decimal system (base 10) which uses ten digits, from 0 to 9. In general, we could use any numbering system.

Computer scientists often use systems based on 8 or 16. The numbering system based on K uses K digits with a value from 0 to K-1. Suppose a natural number M is given, written in the decimal system To convert it to the corresponding writing in the system based on K, we successively divide M by K until we reach a quotient that is less than K

The representation of M in the system based on K is formed by the final quotient (as first digit) and is followed by the remainder of the previous divisions**For example :**

- If M=122 and K=8, 122 in base 10= 172 in base 8 This means that the number
- In decimal system = 172 in octal system.
- 172 in base 8 = 1*8^2 + 7*8 + 2 = 122

You made the following observation in applying the above rule of converting natural numbers to another numbering system

- In some cases in the new representation all the digits of the number are the same. For example 63 in base 10= 333 in base 4

Given a number M in its decimal representation, your task is find the minimum base B such that in the representation of M at base B all digits are the same.

**Input Format**

- The first line contains an integer, M, denoting the number given

**Constraints**

- 1 <= M = 10^12

**Sample Input 1 :**

41

**Sample Output 1 :**

40

**Explanation :**

Here 41 in base 40. will be 11 so it has all digits the same, and there is no smaller base satisfying the requirements

**Sample Input 2 :**

34430

**Sample Output 2 :**

312

**Explanation :**

Here 34430 in base 312 will have all digits the same and there is no smaller base satisfying the requirements

**Example Programs:**

**JAVA PROGRAM**

import java.util.*; class Main { public static boolean convertBase (int m, int base) { int rem = m % base; m = m / base; while (m >= base && (m % base == rem)) m = m / base; if (m == rem) return true; return false; } public static void main (String[]args) { Scanner sc = new Scanner (System.in); int m = sc.nextInt (); int base = 2; while (convertBase (m, base) != true) base++; System.out.println (base); } }

**Q) **You have been given a string S of length N. The given string is a binary string that consists of only 0’s and ‘1’s. Ugliness of a string is defined as the decimal number that this binary string represents.

** Example:**

- “101” represents 5.
- “0000” represents 0.
- “01010” represents 10.

There are two types of operations that can be performed on the given string.

- Swap any two characters by paying a cost of A coins.
- Flip any character by paying a cost of B coins
- flipping a character means converting a ‘1’to a ‘0’or converting a ‘0’ to a ‘1’.

Initially, you have been given coins equal to the value defined in CASH. Your task is to minimize the ugliness of the string by performing the above mentioned operations on it. Since the answer can be very large, return the answer modulo 10^9+7.

**Note:**

- You can perform an operation only if you have enough number of coins to perform it.
- After every operation the number of coins get deducted by the cost for that operation.

**Input Format**

- The first line contains an integer, N, denoting the number of character in the string
- The next line contains a string, S, denoting the the binary string
- The next line contains an integer, CASH, denoting the total number of coins present initially
- Next will contains an integer, A, denoting the cost to swap two characters.
- Then the next line contains an integer, B, denoting the cost to flip a character.

**Constraints**

- 1 <= N <= 10^5
- 1< len(S)<= 10^5
- 1<=CASH <=10^5
- 1<=A<=10^5
- 1<=B<=10^5

**Sample Input 1 :**

4

1111

7

1

2

** Sample Output 1 :**

1

** Explanation:**

3 flips can be used to create “0001” which represents 1.

** Sample Input 2:**

6

111011

7

1

3

** Sample Output 2:**

7

** Explanation:**

First swap 0 with the most significant 1, then use flip twice first on index one and then on index two “111011”=>”0111111″=>”001111″=>”000111″ the value represented is 7.

** Sample Input 3:**

6

111011

7

3

2

** Sample Output 3:**

3

** Explanation:**

Flip the 3 most significant characters to get “000011” : the value represented by this string is 3.N

**EXAMPLE PROGRAMS**

**JAVA PROGRAM**

import java.util.*; class Main { static String str; static int cash, n, a, b; static void swapf () { char s[] = str.toCharArray (); int i = 0; for (int a = 0; a < s.length; a++) if (s[a] == '1') { i = a; break; } int j = s.length - 1; while (j > i) { if (cash < a) break; if (s[j] == '0') { if (s[i] == '0') i++; else { char temp = s[i]; s[i] = s[j]; s[j] = temp; cash -= a; j--; } } else j--; } str = new String (s); } static void flipf () { char s[] = str.toCharArray (); int i = 0; for (int a = 0; a < s.length; a++) if (s[a] == '1') { i = a; break; } while (cash >= b) { if (i == s.length) break; if (s[i] == '1') { s[i] = '0'; i++; cash -= b; } } str = new String (s); } public static void main (String[]args) { Scanner sc = new Scanner (System.in); n = sc.nextInt (); str = sc.next (); cash = sc.nextInt (); a = sc.nextInt (); b = sc.nextInt (); if (a < b) { swapf (); flipf (); } else { flipf (); swapf (); } System.out.println (Integer.parseInt (str, 2)); } }

**Accenture Hack Diva Coding Questions With Solutions 2024**

**Write a program to check whether the given number is even or odd**

```
import java.util.*;
class ninjaSolution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Please Enter a number!!");
int num = sc.nextInt();
if(num%2==0)
System.out.println(num+" is even");
else
System.out.println(num+" is odd");
}
}
```

**Write a program to print the Fibonacci series.**

```
import java.util.*;
class ninjaSolution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Please enter the limit!!");
int limit = sc.nextInt();
int n1 = 0, n2=1, n3;
System.out.println("Fibonacci series upto "+limit+" numnber");
System.out.print("\n\n"+n1+" "+n2+" ");
for(int i=2;i<limit;i++){
n3 = n1+n2;
n1 = n2;
n2 = n3;
System.out.print(" "+n3+" ");
}
}
}
```

**Print the length of a string without using the string functions.**

```
import java.util.*;
class ninjaSolution {
public static void main(String[] args) {
String str = "Hey Ninja!!";
int len=0;
char[] strCharArray=str.toCharArray();
for(char c:strCharArray){
len++;
}
System.out.println("Lenght of string "+str+" is: "+len);
}
}
```

**Write a code to add two numbers without using arithmetic operations.**

```
class ninjaSolution {
public static void main(String[] args) {
int num1 = 10, num2 = 50;
while (num2 != 0){
int carry = (num1 & num2) ; //CARRY is AND of two bits
num1 = num1^num2; //SUM of two bits is A XOR B
num2 = carry << 1; //shifts carry to 1 bit to calculate sum
}
System.out.println("Sum of 10 and 50 is: "+num1);
}
}
```

**Write a code to print numbers from 1 to 10 without using a loop or recursion in C++.**

```
#include <iostream>
using namespace std;
template<int n>
class PrintZeroToN
{
public:
static void display()
{
PrintZeroToN<n-1>::display();
cout << n << endl;
}
};
template<>
class PrintZeroToN<0>
{
public:
static void display()
{
cout << 0 << endl;
}
};
int main()
{
const int n = 10;
PrintZeroToN<n>::display();
return 0;
}
```

**Print the address of a variable without using a pointer.**

We can directly print the address of a variable using the ‘&’ symbol in c,

```
#include <stdio.h>
int main()
{
int x;
printf("Address of x: %p\n", &x);
return 0;
}
```

**Write a code to check whether a number is prime or not.**

```
import java.util.*;
class ninjaSolution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Please enter a number");
int num = sc.nextInt();
int count=0;
for(int i=2;i<num/2;i++){
if(num%i==0)
count++;
}
if(count>0)
System.out.println("Number is not prime");
else
System.out.println("Number is prime");
}
}
```

Keep an eye on **Dailyrecruitment.in** for the most up-to-date information about upcoming exams and results. Find out about official notices, Exam Patterns, Syllabus, Previous Question Papers, Coding Questions, Aptitude Questions, Expected Cut Off, Results, Merit List, Study Materials, and much more. Now is the time to bookmark in order to take advantage of even more amazing career opportunities.

JOB ALERT ON INSTAGRAM |
FOLLOW NOW>> |

JOB ALERT ON YOUR EMAIL DAILY |
SUBSCRIBE NOW>> |

**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 |