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

Accenture 20Coding questions

Top 20 codes of company drive

Uploaded by

ashuchowdary16
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
5 views

Accenture 20Coding questions

Top 20 codes of company drive

Uploaded by

ashuchowdary16
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 20
Latest Accenture Coding Questions And Answers 2024 for placement Chocolate Distribution (Asked in Accenture On Campus 10 Aug 2022, Slot 2) Problem Description: The function accept ‘teger array 1 as its argument. Each element of ‘arr’ repre sents ‘on. The function needs to return the minimum, nur ates distrib number of chocolates that n 10 be distributed to person so that the difference between the chocole of any two people is minimized. Example: Output: Solution Ta Cod es(arr): rr{-1] - arr[0] eflen(arr) - 4): re en Are Ce 0) CR arr=[10, 4, 12, 3, 1] oot ee rint(result) 2, Parking Lot (Asked in Accenture, On Campus 10 Aug 2022, Slot 3) Problem Description: ‘The function accepts a character array ‘arr’ of size ‘'n’as its argument. Each element of ‘arr repre sents e status of a parking slot, where ‘S’ represents an empty slot and epresents an occu! pied slot. The function needs to return the maximum number of cars that can be parked in the parking lot. It is assumed that two cars cannot occupy the same slot and cars can only park in consecutive empty slots. Example: Input: Output n16 arr: XXXSXXSXXSSXXSXX Solution Da (n, arr) prea Tees per races Dae eer a eee prea (max_cars, current_cars) ae (ea) 3. String Transformation (Asked in Accenture OnCampus 10 Aug 2022, Slot 4) Problem Description: The function accepts a string ‘str’ as its argument. The function needs to return the transformed string by replacing all occurrences of the character ‘a’ with the character’’b’ and vice versa. Example: Input: Output str: abaabbce bbbbaaac Solution Tray Rete eco Eco) Rene Eee Renee Renesas -oe ROCs print(transformed string) 4, Array Equili (Asked in Accenture OnCampus 10 Aug 2022, Slot 5) Problem Description: The function accepts an integer array ‘arr’ of size ‘n’ as its argument. The function needs to return the index of an equilibrium point in the array, where the sum of elements on the left of the index is equal to the sum of elements on the right of the index. If no equilibrium point exists, the function should return -1 Example: Input Output: ns 3 am:13573 Solution : ye (CteE total_sum = sum(arr) iat i Telia): ree ise i TU) 5. Array Rotation (Asked in Accenture OnCampus 10 Aug 2022, Slot 6) Problem Description: The function accepts an integer array ‘arr’ of size ‘n’ and an integer ‘d' as its argument. The func- tion needs to rotate the array ‘arr’ by ‘d’ positions to the right. The rotation should be done in place, without using any additional memory. Example: Input: Output m5 34512 am: 12345 a3 Solution : (ee CT) (art, n.d) eee] Tin range(n-1, d= 1,-1} SOE) arrd] = temp 6. Substring Search (Asked in Accenture On Campus 10 Aug 2022, Slot 7) Problem Description: The function accepts two strings ‘str1’ and ‘str2’ as its argument. The function needs to return the index of the first occurrence of substring ‘str2’ in string ‘str1’ or -1 if the substring is not found Example: Input: Output str1: "Hello, World!” 7 str2: World” Solution Ca Crane). 7. Palindrome Check (Asked in Accenture OnCampus 10 Aug 2022, Slot 8) Problem Description: The function accepts a string ‘str’ as its argument. The function needs to determine whether the string is a palindrome or not. A palindrome is a word or phrase that reads the same backward as forward, Example: Input: Output str: "madam" 1 Solution: Cee) Seas Cem t} 8. Reverse Words (Asked in Accenture OnCampus 10 Aug 2022, Slot 9) Problem Description: The function accepts a string ‘str’ as its argument. The function needs to reverse the order of the words in the string. Example: Input Output str: "Hello, World!” ‘dlroW ,olleH Solution: ec) roc oe eer Sa ee (str_input) 9. Find Two Numbers with Sum N Problem Description: Given an array of integers and an integer sum, find a pair of numbers (a, b) in the array where a +b = sum. Example: Input: Output An array of An array of two integers representing the pair (a,b) or -1 ifno integers such pair exists An integer sum Explanation: Given an array of integers, such as [5, 2, 4, 1, 3], and an integer sum, such as 9, the algorithm should determine that the pair (a, b) = (2, 7) or (4, 5) satisfies the condition a +b = sum. Ifno such pair exists, the algorithm should return -1 Solution Cry Cray (ien(arr) - 1) PCa Cu) PORE eet G cP arr=[ ern (cuaemal 10. Maximum Subarray Sum Problem Description: Given an array of integers, find the maximum subarray sum. A subarray is a contiguous subse- quence of the array. Eample: Input: Output: An array of integers ‘An integer representing the maximum subarray sum Explanation: Given an array of integers, such as [-2, 1, -3, 4,- +2,1,-5, 4], the algorithm should determine that the maximum subarray sum is 6 ([4, -1, 2, 1). Solution Java Python rer Ca aru) CTE tB crac COME a ea) max_so_far Gee nee 11. Character Replacement Problem Description Given a sting sr, a character ch1, and a character ch2, replace all ccurtences of cht in str with ch2 and vice versa Input: output ‘The modified string str where all occurrences of ch? are re Astring st placed with ch2 and vice versa A character cht Example: Input: output str= "apples", cht ='2, ch ‘paales Solution imum Value and Its Index in the Array Problem Description: Given an integer array, find the minimum value and its index in the array, Input Output An integer The minimum value and its index, separated by a newline array character Example: Input Output: 15, 2,4, 1,3] 13 Solution Goes i CAC SOR Eee) DO eGuamtes YGaumicss 13. Find the Average of All Positive Numbers in an Array Problem Description: Given an array of integers, find the average of all positive numbers in the array. Input: Output: An integer The average of all positive numbers, or -1 if there are no posi- array tive numbers Example: Input: Output: (5,2,-4,1.3] 3 Solution Je aa) ug oe eee Cee Cres total +=num fetes ' result) ea) 14. Count the Occurrences of a Given Element an Array Problem Description: Given an integer array and an integer element, count the number of occurrences of the element in the array. Input: Output An integer array The number of occurrences of the element An integer element Example: Input: Output: 5,2, 4,1, 21,2 2 Solution Dna Crs cy (arr, element): Crs cry a Core Pen Peau result (result) 15. Check if an Array Contains a Given Element Problem Description: Given an integer array and an integer element, check if the array contains the element, Input: Output ‘An integer array True if the element is found, False otherwise ‘An integer element Example: Input: Output: 15,2,4, 1, 3},2 True Solution : acy (arr, element) oH) 16, Problem Statement: Calculate Prime Sum Implement the function: Int CalculatePrimeSum(int m, int); Calculate and return the sum of prime numbers between ‘m’ and ‘n’ (inclusive). Note:0

You might also like