0% found this document useful (0 votes)
44 views

Accenture Latest Coding

accenture coding
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)
44 views

Accenture Latest Coding

accenture coding
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/ 55

Accenture Latest Coding

1. You are given a String S of length N. Your friend wants to know the
number of times his favorite letter C occurs in the string. Your task is
to help your friend find and return an integer value representing the
number of times a character occurs in a particular string.

Note: All the characters in the strings are in lowercase.


Input Specification:
Input 1: A string S.
Input 2: An integer N, representing the length of string.
Input 3: A character C

Output Specification:
Return an integer value representing the number of times a character
occurs in a particular string.

Example 1:
Input 1: helloworld
Input 2: 10
Input 3: l

Output: 3

Python

Java
2. Daniel has a ball. He wants to find the ball's rebound height, which he
dropped from height H with an initial velocity V. After the Nth rebound
the final velocity of the ball is vn. Your task is to help him find and
return an integer value representing the height to which the ball
rebounds after N bounces.

Note: H’ = H*e^(2n), where H’ is the rebound height, e is the


coefficient of restitution and the number of bounces.
e^(n) = V/Vn, where v is the initial velocity and vn is the final velocity

Input Specification:
Input 1: An integer H, representing initial height
Input 2: An integer V, representing initial velocity
Input 3: An integer Vn, representing final velocity
Output Specification:
Return an integer value representing the height to which the ball
rebounds after N bounces.

Example 1:
Input 1: 10
Input 2: 20
Input 3: 5

Output: 160

Python

Java
3. Jack has an array A of length N. He wants to label whether the
number in the array is even or odd. Your task is to help him find and
return a string with labels even or odd in sequence according to
which the numbers appear in the array.

Input Specification:
Input 1: An integer array A, representing the array of numbers
Input 2: A integer N, representing the length of array.

Output Specification:
Return a string with labels even or odd in sequence according to
which the numbers appear in the array.

Example 1:
Input 1: [1,2,3,4,5,6]
Input 2: 6
Output: OddEvenOddEvenOddEven

Python

Java
4. You are given an array A of length N. Your task is to find and return
an integer value representing the difference between the sum of
elements at odd index and XOR of elements at even index.

Input Specification:
Input 1: An integer N, representing the length of the array.
Input 2: An integer array A.

Output Specification:
Return an integer value representing the difference between the sum
of elements at odd index and XOR of elements at even index.

Example 1:
Input 1: 6
Input 2: {10,5,6,3,7,2}

Output: -1
Explanation: Here N is 6 and the array A= {10,5,6,3,7,2}. The sum of
elements at odd positions are 5 + 3 + 2 = 10 and the XOR of
elements at even positions are 10⊕6⊕7 = 11 and the difference is
10-11 = -1. Therefore -1 is returned as the output.

Python

Java
5. Noah is given an integer array A of length N. He must perform the
following operations on the array.
Select any integer pairs from the array with their sum equal to 18.
From this select the pair with the maximum product such that the first
element of the pair is greater than the second element of the pair.
Your task is to help Noah find and return a pair in the form of an
integer array which satisfies the conditions mentioned.
Input Specification:
Input 1: An integer value N, representing the size of array A.
Input 2: An integer array A.

Output Specification:
Return a pair in the form of an integer array which satisfies the
conditions mentioned.

Example 1:
Input 1: 8
Input 2: {11,1,2,8,10,11,15,7}

Output: {10,8}

Python
Java
Python — Optimised

Java — Optimised
6. Special Fibonacci
Alex is exploring a series and she came across a special series in
which f(N) = f(N-1) * f(N-1) + f(N-2) * f(N-2)
Where f(0) = 1, f(1) = 1
Your task is to help Alex find and return an integer value, representing
the Nth number in this special series.
Note: Return the output modulo 47.

Input Specification:
Input 1: An integer value N.

Output Specification:
Return an integer value representing the Nth number in the special
series
Example 1:
Input: 8
Output: 19

Python

Java
7. You are given a string S and your task is to find and return the count
of permutation formed by fixing the positions of the vowels present in
the string

Example 1:
Input 1: ABC
Output 1: 2

Example 2:
Input 2: CDF
Output 2: 6

Python
Java
8. Ian has been given an Array A of length N and he wants to find the
sum of even positions after reversing the array. Your task is to help
him find and return an integer value representing sum of the array
elements present at the even index of the reversed array.

Input Specification:
Input 1: A reversed integer array A
Input 2: An integer N, representing length of the array.

Output Specification:
Return an integer value representing sum of the array elements
present at the even positions of the array.

Example 1:
Input 1:{10,20,30,40,50,60}
Input 2: 6

Output: 120

Python

Java
9. Bob goes to supermarket to shop candies represented by an array A
for halloween party , his mother gave him some money M. Due to the
festive season, there are several offers in the supermarket. One such
offer useful for Bob is, if the price of the candy is a multiple of 5, he
can buy it without spending any money otherwise he will spend
money equal to Ai which is the price of a particular candy. Bob can
shop as long as he has money. Your task is to find and return the
maximum number of candies Bob can buy.

Note: Assume 1- based indexing.


Input Specification:
Input 1: An integer value, representing number of candies.
Input 2: An integer array A, representing price of each candy.
Input 3: An integer value M, representing the amount of money.

Output Specification:
Return the number of candies Bob can buy.

Example 1:
Input 1: 3
Input 2: {5, 5, 105}
Input 3: 16

Output: 3

Example 2:
Input 1: 4
Input 2: {5, 5, 18, 2}
Input 3: 18

Output: 3

Python
Java
10. Canopy Area
You are developing a feature for an environmental awareness app
that helps users to know how much area their tree’s shadow covers.
You have the distance D from a tree’s trunk to the edge of the
shadow. Your task is to calculate and return an integer value
representing the shadow area of the canopy.

Note: Round off the result to nearest integer


Input Specification:
Input 1: An integer value D, representing the distance from the tree
trunks to the edge of shadow.

Output Specification:
Return an integer value representing the shadow area of the canopy.

Example 1:
Input 1: 5
Output: 78

Explanation: Here, D = 5. So area of the canopy would be 3.14*5*5


= 78.5. Therefore, 78 will be returned as output.

Python

Java
11. Name Entry

Your friend has made entry of a name in the form first name F and
last name L in your contact list. But some letters are in uppercase
while others are in lowercase. Your task is to find and return a string
representing the names such that the first name of your contact is in
lowercase, and the last name of your contact is in uppercase.

Input Specification:
Input 1: A string F, representing the first name
Input 2: A string L, representing the last name

Output Specification:
Return a string representing the names such that the first name of
your contact is in lower case, and the last name of your contact is in
upper case.

Example 1:
Input 1: Accenture
Input 2: program

Output: accenture PROGRAM

Python

Java

12. You are on a hiking trail represented by an array A of length N,


where the trail initially ascends and then descends forming a single
peak. Your task is to find and return an integer value representing the
elevation of the summit.
SAMPLE INPUT 1:
1234321
7
SAMPLE OUTPUT 1:
4
SAMPLE INPUT 1:
0210
4
SAMPLE OUTPUT 1:
2

Python

Java
13. Magical Number
You are given a program to find the count of magical numbers from 1
to N. A magical number is defined by the following criteria:

● Convert each number in the range 1 to N (inclusive) to its binary


representation.
● Replace ‘0’ with ‘1’ and ‘1’ with ‘2’ in the binary string.

Your task is to find and return an integer value representing the count
of the magical numbers present within the given range.
Input Specification:
Input 1: An integer value N representing the range of numbers

Output Specification:
Return an integer value representing the count of magical numbers
present within the range.

Example 1:
Input 1: 2
Output: 1

Input 2: 5
Output: 2

Python

Java
14. Financial Dataset
You are working on a financial analyzing tool which represents the
daily stock prices of a company over a time. Each element in an
integer array A of size N represents the closing price of the stock for
a particular day. Your task is to find and return an integer value
representing the total number of data where the stock price
decreased, indicating negative growth.

Input Specification:
Input 1: An integer array a containing the closing price of the stock.
Input 2: An integer value N representing the size of array.

Output Specification:
Return an integer value representing the total number of days where
the stock price decreased, indicating negative growth.

Example 1:
Input 1: {3,5,6, -7, 9, 10,-12}
Input 2: 7

Output: 2

Python

Java
15. Refueling Vehicle
You are incharge of a convoy of N vehicles, each with fuel meter
which shows the fuel present in each vehicle in litres. Each vehicles
need to travel a distance of X kilometers. If the fuel becomes empty
before reaching X kilometers the vehicle can refuel but the refueling
will be of X litres and if the vehicles completes the X kilometers where
fuel is left over then the extra fuel will be given to the next vehicle in
the convoy. You must rearrange the convoy such that the vehicles
take minimum refueling stops.
Your task is to find and return an integer value representing the
minimum number of refueling stops required by the convoy of
vehicles.
Note:
The vehicles can go 1 kilometer in a single litre.
The refueling at any point of time will be for X litres only.
Input Specification:
Input 1: An integer value X, representing the distance to be travelled.
Input 2: An integer value N, representing the number of vehicles in
the convoy.

Example 1:
Input 1: 100
Input 2: 4
Input 3: {80, 120, 90, 70}

Output: 1

Explanation:
Here the fuel capacity of each of the 4 vehicles is {80, 120, 90, 70}
and X is 100. The refueling of the vehicles will happens as follows:
1. First, the vehicle with maximum fuel capacity of 120 will travel.
It can reach without refueling.
2. Now, we can carry over the remaining fuel of 20(120-100) and
add it to the capacity of the second vehicle, 90. Sp new
capacity becomes 110 (90+20). It can reach without refueling.
3. Then, we can carry over the remaining fuel of 10 (110-100) and
add it to the capacity of the third vehicle, 80. So its new
capacity becomes 90(80+10). Now it requires 1 refueling (which
is X= 100) is required. So the capacity becomes 190(90+100)
and now this vehicle can also reach.
4. Finally, we carry over the remaining fuel of 90(190-100) and
add it to the capacity of the fourth vehicle, 70.So its new
capacity becomes 160(70+90), So it can reach without
refueling.
The convoy of vehicles requires 1 refueling. Therefore 1 is returned
as the output.
Example 2:
Input1: 120
Input 2: 6
Input 3: {90, 120, 110, 105, 80, 70}

Output: 2

Python

Java
16. Chocolate Jar
You are given an integer array of size N, representing jars of chocolates.
Three students A, B, and C respectively, will pick chocolates one by one
from each chocolate jar, till the jar is empty and then repeat the same with
the rest of the jars, Your task is to find and return an integer value
representing the total number of chocolates that student A will have, after
all the chocolates have been picked from all the jars

Input Specification:
Input 1: An integer array representing the quantity of chocolates in each
jar.
Input 2: An integer value N representing the number of jars.

Output Specification:
Return an integer value representing the total number of chocolates that
student A will have after all the chocolates are picked.

Example 1:
Input 1: {10, 20, 30}
Input 2: 3

Output: 21
Explanation:
Jar1: 10 chocolates-> A-4, B-3,C-3
Jar2: 20 chocolates-> A- 7,B-7,C-6
Jar3: 30 chocolates-> A-10,B-10,C-10

So A gets a total 4+7+10=21 chocolates.

Example 2:
Input 1: {3, 2, 6}
Input 2: 3

Output: 4

Python
Java

17. Stabilize the System


In a tech startup, the team faced a software bug - the zeros in their data
outputs were causing their system to crash. A junior developer suggested
replacing all the 0’s with 5’s as a quick fix. By implementing this simple
code tweak, they stabilized the system. Your task is to find and return an
integer value representing the value that stabilizes the system.

Input Specification:
Input 1: An integer value

Output Specification: Return an integer value representing the value that


stabilizes the system.

Example 1:
Input 1: 100067
Output: 155567

Python

Java
18. Prime Number Picnic

You are planning a picnic for a group of friends who love math. TO make it
interesting you decided to bring unique numbers of items N. Your task is to
find and return an integer value representing the sum of all the prime
numbers till N. In case, the number of items is 0 or 1 return 0.

Note: Prime numbers are natural numbers that are divisible by only 1 abd
the number itself.

Input Specification:
Input 1: An integer value N.

Output Specification:
Return an integer value representing the sum of all the prime numbers till N
in case that number of items is 0 or 1 return 0.

Example 1:
Input: 5
Output: 10

Python
Java
19. Poet and Rhymes

A poet has asked you for assistance in writing poems. He has given you a
string S and a dictionary D and he asks you to find from the dictionary, a
word which rhymes best with S. Words are said to rhyme when the last
syllables of the words are the same, like “cave” and “gave”, or “typical” and
“critical”, The words will be deemed to rhyme best if the last few characters
of the words match the most.

Your task is to find and return a string value denoting the word which
rhymes best with S, from the dictionary D. If no such word is found return
the string “No Word”.

Note:
If all the characters match, it is same word and not a rhyming word.
All the given words are in lowercase.
If multiple rhyming words are found, then choose the word with the least
index.

Input Specification:
Input 1: A string value S, representing a single word.
Input 2: A string array D, representing the dictionary.
Input 3: An integer value representing the length of array D.

Output Specification:
Return a string value denoting the word which rhymes best with S from the
dictionary D, if no such word is found return the string “No Word”.

Example 1:
Input 1: thunder
Input 2: {puzzle, thunder, powder, blender, under}
Input 3: 5

Output: under

Python
s = input()
d = input().split()
n = int(input())
max_len = 0;w=""
for word in d:
if s!=word:
curr=0
word = word[::-1]
s=s[::-1]
i=0
while i<min(len(s),len(word)):
if s[i]!=word[i]:
break
curr+=1
i+=1
if curr>max_len:
max_len = curr
w=word
#print(word)

print(w[::-1])
print(max_len)

Java
20. File Version
You are given a string array S that contains the name of some files along
with their versions. Your task is to find and return an integer value
representing the latest version out of all the files that are correctly named in
the array. A file is considered correct if it follows the format of the file names
as “FILE_X” (where X represents the file version number). Return -1 if there
are no correct files in the array

Note:
A file is incorrect if the name of the file does not match the format.
If there is no file in the files array then also return -1.
Input Specification:
Input 1: A string array S, representing the names of the files.
Input 2: An integer value representing the size of the array.

Output Specification:
Return an integer value representing the latest version out of all the files
that are correctly named in the array.

Example 1:
Input 1: {File_1, File_2, File_3}
Input 2: 3

Output: 3

Python
Java

21. White Space difference

You are given 2 strings A and B. Your task is to find and return a string
Saying ‘Even’ if the value representing the absolute differences between
the number of whitespaces in both the strings is divisible by 2 else ‘Odd’ if
the value representing the absolute differences between the number of
whitespaces in both the strings the whitespace is not divisible by 2 along
with the difference value

Input Specification:
Input 1: A string A
Input 2: A string B

Output Specification:
Return a string saying ‘Even’ if the value representing the absolute
differences between the number of white spaces in both the strings is
divisible by 2 else ‘Odd’ if the value representing the absolute differences
between the number of whitespaces in both the strings the whitespaces is
not divisible by 2.

Example 1:
Input 1: “He ll o W or ld”
Input 2: “Hello World”

Output: Even4

Python

Java
22. Product Pair
You are given an integer array A of length N and your task is to find and
return an integer value representing the count of unique pairs whose
products are multiples of 3.

Note: A Unique pair means that the elements must be the same regardless
of their order. For instance, (1,3) and(3,1) are considered as the same pair.

Input Specification:
Input 1: An integer value N, representing the size of the array
Input 2: An integer array A.

Output Specification:
Return an integer value representing the count of unique pairs whose
products are multiples of 3.

Example 1:
Input 1: 4
Input 2: {3,6,5,4}

Output: 5

Python

Java
23. Island Life

You are stuck on island where they sell and eat coconut sweets only. A
person can buy at most 1 box per day with each box containing N pieces.
To remain alive, you must consume E coconut sweets daily for D dyas, but
the catch is that you cannot purchase sweets on Sundays. Your task is to
find and return an integer value representing the minimum number of times
you have to buy coconut sweets in order to stay alive. If not possible, return
-1.
Note: The day starts from Monday

Input Specification:
Input 1: An integer value N, representing the number of coconuts sweets
per box.
Input 2: An integer value E, representing the number of coconut sweets
you must eat daily.
Input 3: An integer value D, representing the number of days you have to
spend on the island.

Output Specification:
Return an integer value representing the minimum number of times you
have to buy coconut sweets in order to stay alive. If not possible return -1.

Example 1:
Input 1: 10
Input 2: 2
Input 3: 10

Output: 2

Python
Java
24. Qualifying Score

There is a competition in a school. A qualifying score of 35 marks or more


has been set as the cut-off to take part in this competition.
There are N subjects taught in a class. The marks obtained in each subject
in semesters 1 and 2 are given in the form of two arrays S1 and S2
respectively. The qualifying score is calculated in the following way:
● Step 1: Subtract the marks obtained in the ith subject in Semester 1
from the marks obtained in the ith subject in Semester 2, i.e., S2[i] -
S1[i], where i = 0, 1, 2,....
● Step 2: Add the marks of up to P subjects with the maximum scores
obtained after the subtraction in Step 1. This will give a student’s
qualifying score. The aim is to get a score equal to or greater than 35.
If the qualifying score is greater than or equal to 35 then the student
qualifies to participate in the competition, else they are disqualified.
Your task is to find and return a string value, representing the result
‘Qualified’ or ‘Disqualified’ followed by the score achieved (Separated
by a space).

Example 1:
Input 1: 5
Input 2: 3
Input 3: [10, 20, 30, 40, 50]
Input 4: [30, 45, 35, 45, 60]

Output: True

Python

Java
25. Find Dividend
Given array arr, divisor, quotient, remainder as input.
Formula: Dividend = quotient*divisor+remainder.

Calculate the dividend and check whether the dividend os present in the
array or not. If present return index else -1.

Sample Input 1: Sample Input 2:

4 4

2468 2468

D=1 2

Q=2 4

R=0 1

Sample Output 1: Sample Output 2:

0 -1
26. Printing Job

There is a printing shop where the customers submit their print jobs al
regular intervals, and each job takes a fixed amount of time to complete.
You are given an integer value N denoting the total number of print jobs,
and X denoting the line duration after which the next print job arrives.
Your task is to find and return an integer value representing how long the
last job will have to wait in the queue considering one print will take exactly
10 minutes. case, there is no waiting time then return 0.
Input Specification:
input1: An integer value N representing the number of printing jobs
input2: An integer value X representing the time duration after which the
next print job arrives.
Output Specification:
Return an integer value representing how long the last job will have to win
the queue considering one print will take exactly 10 minutes. If in case
there waiting time then return 0.
Example 1:
input1:4
input2:5
Output: 15
Explanation:
Here, N = 4 and x = 5 Time to complete one print job is 10 mins. So, the
time needed for three prints is 3^ * 10 = 30 . The last print job arrives at 15
minutes (75), 50 the waiting time is 30-15 15. Hence, 15 is returned as the
output.

Example 2:
input1: 3
input2: 10
Output: 0
Explanation:
Here, N = 3 and X = 10 time to complete one print job is 10 mins, So, the
time needed for 2 prints is 2^ * 10 = 20 , The last print job arrives at 20
minutes (2*10). So, the waiting time is 20-20 = 0. Hence, 0 is returned as
the output

Python

Java

You might also like