Skip to main content

Posts

Persistent Coding Questions and Answer in 2022 - Question 3

Persistent Coding Questions and Answer in 2022 Problem Statement : Given an unsorted array of n elements, find if the element k is present in the array or not. Complete the findNumber function in the editor below. It has 2 parameters: 1.    An array of integers,arr,denoting the elements in the array. 2.    An integer,k,denoting the element to be searched in the array. The function must return a string “YES” or “NO” denoting if the element is present in the array or not. Input Format The first line contains an integers n,denoting the number of elements in the array arr. Each line i of the n subsequent lines (where 0<=i<=n) contains an integer describing arri. The next line contains an integer,k,the elements that needs to be searched. Constraints 1 <= n <= 105 1 <= arr[i]<= 109 Output Format The function must return a string “YES” or “NO” denoting if the element is present in the a...

Persistent Coding Questions and Answer in 2022 - Question 2

  Persistent Coding Questions and Answer in 2022 Problem Statement : Flipkart has been infected with a virus, the virus works this way: Each user that has been infected with the virus is traced by a special algorithm and a hint that the virus gives. The virus leaves a hint number N. Flipkart is able to identify the user ID of the virus by this N number as the user ID works as a series : Each number in the series is the sum of the last three numbers in the series. The first three numbers in the series are 0, 0, 1 always. Write a program to identify the user ID infect based on N value checked from the logs of the system Input The input contains the N value left by the virus and found by engineers in the logs of the system Output Print the userID of the infect user.   Example Input 11 Output  81   Example Input 16 Output  1705   Program :              ...

Persistent Coding Questions and Answer in 2022 - Question 1

  Persistent Coding Questions and Answer in 2022 Problem Statement : Sajith loves numbers and coding. His dad gives a task to write a code to find the nth largest number in an array. Input  The inputs have : First the count of integers and the second n value The second line of the input has the list of integers that he needs to do the operations upon. Output You have to print the integer representing the nth largest out of the numbers given by his father Constraints 0 < value n <=  count of integers <= 10^6 -10^6 <= each integer <= 10^6 0 <= i < count of integers Example Input 5  3 11 -1 – 4 12 -6 Output  -1 Explanation  : -1 is 3rd largest Program :   n,k=map(int,input("Enter a Numbers : ").split()) print(sorted(list(map(int,input("list of Integer : ").split())))[-k]) for execution and output so check the video :

Accenture Coding Questions and Answers 2021 - Question 13

    Accenture Coding Questions and Answers  2021 Problem   Description : You are required to input the size of the matrix then the elements of matrix, then you have to divide the main matrix in two sub matrices (even and odd) in such a way that element at 0 index will be considered as even and element at 1st index will be considered as odd and so on. then you have sort the even and odd matrices in ascending order then print the sum of second largest number from both the matrices Example enter the size of array  : 5 enter element at 0 index  : 3 enter element at 1 index :  4 enter element at 2 index  : 1 enter element at 3 index :  7 enter element at 4 index  : 9 Sorted even array : 1 3 9 Sorted odd array : 4 7 7 Program : array = [] evenArr = [] oddArr = [] n = int(input("Enter the size of the array:")) for i in range(0,n):     number = int(input("Enter Element at {} index:".format(i)))...

Accenture Coding Questions and Answers 2021 - Question 12

  Accenture Coding Questions and Answers  2021 Problem   Description : You are required to implement the following function: Int Calculate(int m, int n); The function accepts 2 positive integer ‘m’ and ‘n’ as its arguments.You are required to calculate the sum of numbers divisible both by 3 and 5, between ‘m’ and ‘n’ both inclusive and return the same. Note 0 < m <= n Example Input: m : 12 n : 50 Output 90 Explanation: The numbers divisible by both 3 and 5, between 12 and 50 both inclusive are {15, 30, 45} and their sum is 90. Sample Input m : 100 n : 160 Sample Output 510   Program : m = int(input("M:")) n = int(input("N:")) def calculate(m, n):     sum = 0     for i in range(m,n+1,1):         if i%3 == 0 and i%5 == 0:             sum = sum + i     print(sum) calculate(m,n) ...

Accenture Coding Questions and Answers 2021 - Question 11

  Accenture Coding Questions and Answers  2021 Problem   Description : You are given a function, Int MaxExponents (int a , int b); You have to find and return the number between ‘a’ and ‘b’ ( range inclusive on both ends) which has the maximum exponent of 2. The algorithm to find the number with maximum exponent of 2 between the given range is Loop between ‘a’ and ‘b’. Let the looping variable be ‘i’. Find the exponent (power) of 2 for each ‘i’ and store the number with maximum exponent of 2 so faqrd in a variable , let say ‘max’. Set ‘max’ to ‘i’ only if ‘i’ has more exponent of 2 than ‘max’. Return ‘max’. Assumption:  a <b Note : If two or more numbers in the range have the same exponents of  2 , return the small number. Example Input: 7 12 Output: 8 Explanation: Exponents of 2 in: 7-0 8-3 9-0 10-1 11-0 12-2 Hence maximum exponent if two is of 8.   Program : def countExponents(i):   ...

Accenture Coding Questions and Answers 2021 - Question 10

  Accenture Coding Questions and Answers  2021 Problem   Description : You are given a function, Void *ReplaceCharacter(Char str[], int n, char ch1, char ch2); The function accepts a string  ‘ str’ of length n and two characters ‘ch1’ and ‘ch2’ as its arguments . Implement the function to modify and return the string ‘ str’ in such a way that all occurrences of ‘ch1’ in original string are replaced by ‘ch2’ and all occurrences of ‘ch2’  in original string are replaced by ‘ch1’. Assumption:  String Contains only lower-case alphabetical letters. Note: Return null if string is null. If both characters are not present in string or both of them are same , then return the string unchanged. Example: Input: Str: apples ch1:a ch2:p Output: paales Explanation: ‘A’ in original string is replaced with ‘p’ and ‘p’ in original string is replaced with ‘a’, thus output is paales.   Program : def swap (user_input, str1, str2): ...