0% found this document useful (0 votes)
39 views5 pages

Accenture

Uploaded by

shaktisaali30
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)
39 views5 pages

Accenture

Uploaded by

shaktisaali30
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/ 5

Accenture Coding Questions

Hiringhustle

1.Write a function SmallLargeSum(array) which accepts the array as an


argument or parameter, that performs the addition of the second largest
element from the even location with the second largest element from an odd
location?
Rules:
a. All the array elements are unique.
b. If the length of the array is 3 or less than 3, then return 0.
c. If Array is empty then return zero.
Sample Test Case 1:
Input:
6
321754
Output:
7
Explanation: The second largest element in the even locations (3, 1, 5) is 3. The
second largest element in the odd locations (2, 7, 4) is 4. So the addition of 3
and 4 is 7. So the answer is 7.
Sample Test Case 2:
Input:
7
4079642
Output:

Accenture Coding Questions Hiringhustle 1


10

def SmallLargeSum(array):
if len(array) == 0 or len(array) <= 3:
return 0

even_indices = array[::2]
odd_indices = array[1::2]

even_indices.sort(reverse=True)
odd_indices.sort(reverse=True)

if len(even_indices) >= 2 and len(odd_indices) >= 2:


return even_indices[1] + odd_indices[1]
else:
return 0

print(SmallLargeSum([3, 2, 1, 7, 5, 4]))
print(SmallLargeSum([4, 0, 7, 9, 6, 4, 2]))

2.Write a function CheckPassword(str) which will accept the string as an


argument or parameter and validates the password. It will return 1 if the
conditions are satisfied else it’ll return 0?The password is valid if it satisfies
the below conditions:a. It should contain at least 4 characters.b. At least 1
numeric digit should be present.c. At least 1 Capital letter should be there.d.
Passwords should not contain space or slash(/).e. The starting character
should not be a number.

Sample Test Case:


Input:

bB1_89
Output:

Accenture Coding Questions Hiringhustle 2


def CheckPassword(password):
if len(password) < 4:
return 0
if not any(char.isdigit() for char in password):
return 0
if not any(char.isupper() for char in password):
return 0
if ' ' in password or '/' in password:
return 0
if password[0].isdigit():
return 0
return 1

print(CheckPassword('bB1_89'))

3.Write a function CalculateBinaryOperations(str) that accepts the string as


an argument or parameter. The string should contain the binary numbers
with their operators OR, AND, and XOR?a. A Means the AND Operation.b. B
Means the OR Operation.c. C Means the XOR Operation.By scanning the
given string from left to right you’ve to calculate the string and by taking one
operator at a time then return the desired output.Conditions:1.The priority of
the operator is not required.2.The length of the string is always Odd.3.If the
length of the string is null then return -1.

Sample Test Case:

Input:
1C0C1C1A0B1

Output:
1

Explanation:

Accenture Coding Questions Hiringhustle 3


The entered input string is 1 XOR 0 XOR 1 XOR 1 AND 0 OR 1.
Now calculate the string without an operator priority and scan the string
characters from left to right. Now calculate the result and return the desired
output.
Note: This will convert the char into the num (char – ‘0’) in the c++ language.

def CalculateBinaryOperations(binary_string):
if len(binary_string) == 0:
return -1

result = int(binary_string[0])

for i in range(1, len(binary_string), 2):


operator = binary_string[i]
operand = int(binary_string[i+1])

if operator == 'A':
result = result & operand
elif operator == 'B':
result = result | operand
elif operator == 'C':
result = result ^ operand

return result

print(CalculateBinaryOperations('1C0C1C1A0B1'))

4.Write a function FindMaxInArray, which will find the greatest number from
an array with its desired index? The greatest number and its desired index
should be printed in separate lines.

Sample Test Case:


Input:

10

Accenture Coding Questions Hiringhustle 4


15 78 96 17 20 65 14 36 18 20
Output:

96

def FindMaxInArray(array):
max_value = max(array)
max_index = array.index(max_value)
print(max_value)
print(max_index)

FindMaxInArray([15, 78, 96, 17, 20, 65, 14, 36, 18, 20])

Accenture Coding Questions Hiringhustle 5

You might also like