## Accenture Software Development Engineer Hiring Coding Question & Answer!

#### 1. Number of Unique Characters

Problem Statement:
You are required to implement the following function:
NumberUniqueCharacter(str)

The function accepts a string ‘str’ as its argument. You are required to calculate the number of unique characters in string ‘str’ and return the same.

Note:
If ‘str’=NULL, return -1

Assumptions:

• length of ‘str’ <=100000 characters
• ‘str’ contains only lower case alphabets.

Example:

Input
str: abcdabc
Output:
4
Explanation:
The string ‘str’ is “abcdabc”, and unique characters in string ‘str’ are {‘a’,’b’,’c’,’d’}, count of them is 4, hence 4 is returned.

Sample Input
str: efeefhjg
Sample Output
5

### Solution:

Method 1

``````def NumberUniqueCharacter(str):
count=0
temp=""
if str=="":
return -1
for i in str:
if i not in temp:
temp+=i
count+=1
return count
str="abcdabc"
print(NumberUniqueCharacter(str))
``````

Method 2

``````def NumberUniqueCharacter(str):
if str=="":
return -1
str=set(str)
return len(str)
str="abcdabc"
print(NumberUniqueCharacter(str))``````

#### 2. Maximum Index Product

Problem Statement
Implement the following function:
MaxIndexProduct(arr,n)

The function accepts an integer array ‘arr’ of size n. Implement the function to find and return maximum index product. For every index ‘j’, index product =Left(j) x Right(j). Left(j)=an index ‘k’ which is closest to index ‘j’ ,such that k<j and arr[k] > arr[j], if no such index ‘k’ exist then Left(j) = 0. Right(j) = an index ‘l’ which is closest to index ‘j’, such that l > j and srr[l] > arr[j], if no such index ‘I’ exists then Right(j) = 0.

Assumption:
Element at index 0 is the smallest.
Note:

• Return -1 if the array is empty(or None in the case of Python).
• Indexing starts from 0.

Example:
Input
arr: -3 4 3 6 4 5 -2
Output
15
Explanation:
Index Product:

• Index product of index 0 = 0 x 1 = 0
• Index product of index 1 = 0 x 3 = 0
• Index product of index 2 = 1 x 3 = 3
• Index product of index 3 = 0 x 0 = 0
• Index product of index 4 = 3 x 5 = 15
• Index product of index 5 = 3 x 0 = 0
• Index product of index 6 = 5 x 0 = 0
The maximum index product is 15. Thus, the output is 15.

Sample Input
arr: 1 5 4 3 5 2
Sample Output
8

### Solution

``````def maxIndexProduct(arr,n):
product=0
if n==0:
return -1
for j in range(1,n-1):
left=0
right=0
for k in range(j-1,-1,-1):
if arr[k]>arr[j]:
left=k
break
for l in range(j+1,n):
if arr[l]>arr[j]:
right=l
break
if (left*right>product):
product=left*right
return product
ls=[int(x) for x in input().split()]
n=len(ls)
print(maxIndexProduct(ls,n)) ``````

Amazon Software Development Engineering Hiring Coding Question & Answer!

### Manoj Kumar

I Love Technology and like to Explore new Technologies
{"ft_lang_label":"__label__en","ft_lang_prob":0.6280286,"math_prob":0.98152405,"size":2868,"snap":"2022-27-2022-33","text_gpt3_token_len":858,"char_repetition_ratio":0.14141062,"word_repetition_ratio":0.05672269,"special_character_ratio":0.29741982,"punctuation_ratio":0.12881356,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99867535,"pos_list":[0,1,2],"im_url_duplicate_count":[null,3,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-06-28T22:26:06Z\",\"WARC-Record-ID\":\"<urn:uuid:8847eddb-6201-4587-9daf-a168a0ed54f5>\",\"Content-Length\":\"111511\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:a164e470-4667-4095-9538-49072577f79a>\",\"WARC-Concurrent-To\":\"<urn:uuid:5e59b63d-94e0-425b-813e-f13bbc9f602e>\",\"WARC-IP-Address\":\"104.243.45.183\",\"WARC-Target-URI\":\"https://codescript.in/accenture-software-development-engineer-hiring-coding-question-answer/488/\",\"WARC-Payload-Digest\":\"sha1:CBG7R5NO3EDZEDJQRJ3BXD6JMFGUSEFM\",\"WARC-Block-Digest\":\"sha1:PKFITTI4WWK65YDF7OTUQXYTY6ZOAO3C\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-27/CC-MAIN-2022-27_segments_1656103617931.31_warc_CC-MAIN-20220628203615-20220628233615-00709.warc.gz\"}"}