Skip to main content

Posts

Showing posts from April, 2022

InfyTQ Python Coding Question & Answer 2022 - Team Division

  InfyTQ  Python Coding Question & Answer 2022 Team Division Problem Statement -:  Consider an array inarr containing at least two non-zero positive integers ranging between 1 to 300 (inclusive of the boundary values). Divide the integers in inarr into two groups based on the below rules: Each of the integers should belong to either of the two groups The total sum of integers in each of the groups must be as nearly equal as possible The total number of integers between the two groups should not differ by more than 1 Print, outnum1 and outnum2, the sum of the integers of two groups separated by a space. If outnum1 and outnum2 are not equal, then print the smaller sum followed by the larger sum. Input Format: Read the array inarr elements separated by (‘,’) comma. Read the input from the standard input stream. Output Format: Print outnum1 and outnum2 in the required order separated by a space. Print the output to the standard output stream. S...

InfyTQ Python Coding Question & Answer 2022 - Minimum Withdrawals

  InfyTQ  Python Coding Question & Answer 2022 Minimum Withdrawals Problem Statement-: There is a unique ATM in Wonderland. Imagine this ATM as an array of numbers. You can withdraw cash only from either ends of the array. Sarah wants to withdraw X amount of cash from the ATM. What is the minimum number of withdrawals Sarah would need to accumulate X amount of cash. If it is not possible for Sarah to withdraw X amount, return -1.  Input Format  The first line contains an integer, N, denoting the number of elements in ATM.  Each line i of the N subsequent lines (where 0 <= i < N) contains an integer describing the cash in the ATM.  The next line contains an integer, X, denoting the total amount to withdraw.  Constraints  1 <= N <= 10^5  1 <= ATM [i] <= 10^5  1 <= X <= 10^5  Sample Test Cases Sample Input 2 1 1 3  Sample Output -1  Explanation The total amount o...

InfyTQ Python Coding Question & Answer 2022 - Identify Palindrome

  InfyTQ  Python Coding Question & Answer 2022 Identify Palindrome Problem Statement-:  For a given positive number num, identify the palindrome formed by performing the following operations- Add num and its reverse  Check whether the sum is palindrome or not. If not, add the sum and its reverse and repeat the process until a palindrome is obtained  For example:  If original integer is 195, we get 9,339 as the resulting palindrome after the fourth addition:     195 + 591 ————–    786 + 687 ————–    1473 + 3741 ————–    5214 + 4125 ———-   9339 Input format:  Read num from the standard input stream.  Output format:  Print the palindrome calculated to the standard output stream.  Sample Test Cases Sample Input 1 124 Sample Output 1 545 Explanation 1 The sum of 124 and its reverse 421 is 545 which is a palindrome.  Sample i...

InfyTQ Python Coding Questions & Answer 2022 - Four in a line

  InfyTQ  Python Coding Questions & Answer 2022 Four in a line Problem Statement -:  Given a m x n matrix inmatrix of positive integers, print an integer outnum based on the below logic:  Identify all possible sets in inmatrix that contain at least four consecutive elements of the same value val, either horizontally, vertically, or diagonally  If only one set of consecutive elements is identified, store the value val in outnum  If more than one set of consecutive elements is identified, find the smallest value and store it in outnum  If no set of four consecutive elements of the same value is identified either horizontally, vertically, or diagonally, print -1  Assumption:  m and n will be greater than 3  Input format:  First line will contain number of rows m of inmatrix The next m lines will contain the elements of inmatrix. Each line will have n elements separated by space. Read the input from the sta...

InfyTQ Advantage Round Python Coding Questions & Answer 2022 - Divisible by K

  InfyTQ  Advantage   Round Python Coding Questions & Answer 2022 Divisible by K Problem Statement-:   Alice has a non-negative integer x written in the base y (a numeral system where 2 <= y <= 16). The number x has distinct digits. Bob has a number k written in the decimal numeral system. Alice wanted to check if the number x is divisible by the number k. However, Bob thinks it’s a very easy task. That’s why he proposed another problem: count the number of permutations of x which result in a number divisible by k. Alice is confused and doesn’t know how to solve Bob’s problem, can you help her? Notes: y is given in decimal. The possible digits for x start with the usual digits (0-9), and then with the letters (A – F), depending on the value of y. For example, if y = 12 then the digits are [0,1,… 9, A, B]. Also when y = 3, the possible digits are [0,1,2].  Since x may contain letters, it’s inputted as a string.  It’s guaranteed ...

InfyTQ Advantage Round Python Coding Questions & Answer 2022 - Palindromic Paths

  InfyTQ  Advantage   Round Python Coding Questions & Answer 2022 Palindromic Paths Problem Statement-:     You are given a grid of size of N*M (1-based indexing). Each cell in the grid contains a lower case English alphabet (a-z). You have to replace some letters of the grid such that any path from (1,1) to (N,M) is a palindromic path. A path is palindromic if the string obtained by joining letters from the corresponding cells of a traversed path is a palindrome i.e. reads the same forward and backward. You are only allowed to move Right or Down in the grid. Calculate the minimum number of letters that you need to replace such that any valid path from (1,1) to (N,M) is palindromic. Function Description: Complete the palindromicPaths function in the editor below. It has the following parameter(s): Parameters: Name Type Description n Integer Number of rows in the grid ...

InfyTQ Advantage Round Python Coding Questions & Answer 2022 - Alisa In the Library

  InfyTQ  Advantage   Round Python Coding Questions & Answer 2022 Alisa In the Library Problem Statement -:    Alisa is in the library, she wants to buy some different books, there are “nm” different chemistry books and k different science books. In how many different ways can Alisa select a book of mathematics, two books of chemistry, and some books of science? Function Description: Complete the books function in the editor below. It has the following parameter(s): Parameters: Name Type Description n Integer the number of mathematics books m Integer the number of chemistry books k Integer the number of science books x Integer the number of books of science Alisa needs   Return : The function must return an INTEGER denoting the number of ways Alisa can buy t...