Content text Cognizant Online Assessment Questions 2024
Cognizant Coding Questions 2024 (Lets Code) Join telegram & Check Youtube channel for more coding questions Accenture OA Coding questions Note : Do not ask for the access of the doc , you can use it without it! Visit Lets Resource for placement related resources - https://letsresource.in/ If you have any cognizant coding questions then please share it with us to help others! Minimum Sum 18 Sep 2024 ( Lets Cod) You are given two integer arrays A and B of length N on which you have to perform below operation: In one operation, you can swap any two elements of 'A' or any two elements of 'B' Your task is to find and return an integer value representing the minimum possible sum of A[i]*B[i] after performing the above operation any number of times. Note: The operation can also be performed 0 number of times. Input Specification: input1: An integer value N representing the size of arrays. input2: An integer array A input3: An integer array B output Specification: Return an integer value representing the minimum possible sum of A[i]*B[i] after performing the above operation any number of times. Example 1: input1: 4 input2: {1,4,1,6} input3: {1,4,3,4} Output : 25 Explanation: Here A = {1,4,3,2} and B = {1,4,3,4}. To minimize the sum, we can swap the first two elements of A i.e., 4 and 1. The array will now become (4,1,3,2). The sum obtained will be 25, which is the minimum. Hence, 25 is returned as the output.
Example 2: input1:3 input2: (4,1,6) input3: (3,1,2) Output : 17 Explanation: Here, A = (4,1,6) and B= (3,1,2). To minimize the sum, we can swap the first two elements of A. i.e., 4 and 1 and the last two elements of B i.e., 1 and 2. The array A and B will now become (1,4,6) and (3,2,1) respectively. The sum obtained will be 17, which is the minimum. Hence, 17 is returned as the output. Magical Library 18 Sep 2024 ( Lets Cod) In a magical library, each bookshelf is represented by a two-dimensional array A, where each row of the 2D array A[i] represents the series value of a book. A row is considered magical if the sum of the odd values of the series of a book is even. Your task is to find and return an integer value representing the number of magical rows. Input Specification: input1: An integer value representing the number of rows in the 2D array. input2: An integer value representing the number of columns in the 2D array. input3: A 2D integer array where each row represents a series of books. Output Specification: Return an integer value representing the number of magical rows. Example 1: input1: 3 input2:3 input3: ((1, 2, 3), (4, 5, 6), (7, 8, 9)) Explanation: Here, the given 2D array is {{1, 2, 3} , {4, 5, 6}, {7, 8, 9}} - In the first row {1, 2, 3} the odd numbers are {1, 3} and their sum is 4 which is even. - In the second row {4, 5, 6} the odd numbers are {5} and as there is only one odd element so the sum is 5 which is odd. - In the third row {7, 8, 9} the odd numbers are {7, 9} and their sum is 16 which is even. Therefore, there are only 2 magical rows so, 2 is returned as the output. Example 2: input1 : 3
input2 : 2 input3: {{2, 4} (0,0), {11, 11}} Output: 1 Explanation: Here, the given 2D given array {{2, 4} (0,0), {11, 11}} , Only the last row {11, 11} has odd elements and their sum is 22 which is even. Therefore, there is only 1 magical row so, 1 is returned as the output Knowledge Enhancement 18 Sep 2024 ( Lets Cod) Alex is a high school student who loves reading and has a summer break coming up. He has a list of books he wants to read, with each book's estimated reading time stored in an array A. Alex has N hours available during the break for reading. Your task is to help Alex determine the maximum number of books he can read without exceeding his total available reading hours. Input Specification: - input1: An integer array A, where each element represents the estimated time to read each book. - input2: An integer N, representing the total number of hours Alex has available for reading. - input3: An integer size, representing the size of the array A. Output Specification: - Return an integer value representing the maximum number of books Alex can read without exceeding his total available reading hours. Example 1: - input1: [4, 2, 3, 1] - input2: 5 - input3: 4 Output: 2 Explanation: Here N=5 and Alex has 4 books with reading times of 4, 2, 3, and 1 respectively then • The optimal way to utilize the 5 hours is to read the books with reading times of 2 and 1 hour. • If he starts reading the book within 3 hours, then it will exceed the time limit. The maximum number of books that can be read is 2. Hence. 2 is returned as output
The Distance 18 Sep 2024 ( Lets Cod) Jim has a password represented by a string S consisting of lowercase English letters (a-z) and digits (0-9). The distance between two characters is defined as the absolute difference between their indices in the string. Your task is to find and return the maximum distance between two non-similar characters within the given password S. Note: The distance between two adjacent characters is 1. Input Specification: - input1: A string S containing lowercase English letters (a-z) and digits (0-9). Output Specification: - Return an integer representing the maximum distance between two non-similar characters within the given password S. Example 1: - Input: abc10 - Output: 4 Explanation: In the string abc10, the maximum distances between non-similar characters are: 1. Between a and 0 (indices 0 and 4): Distance is 4. 2. Between b and 0 (indices 1 and 4): Distance is 4. Other combinations yield a shorter distance. Therefore, the maximum distance between two non-similar characters is 4. Example 2: