Coding Capgemini

You might also like

You are on page 1of 50
aay logi work ‘The online English language skills learning website 'EngAtTip' has designed an assessment. In the assessment, a piece of text is displayed to the students, The text contains space-separated words. A word is an alphabetic sequence of characters with no \whitespaces in between the characters, The students must identify the words that are repeated in the text more than or equal to NN times. These repeated words are automatically removed by the system before the next text is displayed to the students. The texts do not contain any punctuation marks. ‘Write an algorithm to display the words that are repeated more than or equal to N times in the text Note ‘text input is case-sensitive (.e, ‘mat’ and 'MAT' are considered as different words, not the same).The text can contain lowercase and uppercase letters from the English alphabet (i.e. a2, A-Z]. All uppercase letters come before lowercase letters in lexicographical order. Input Sample 1 input cat batman latt matter cat matter cat cat latt ltt Rowlett * ‘at batman latt matter cat matter eat cat lat latt Output: cat latt 2 Explanation bial The word "cat" is repeated four times and the word "Iatt”is repeated three times in the text. Hence the words that will be removed are ["cat”, "latt") oe > a od cae po ae yo 2) Problem statement 4 workS The IT giant “SoftCompinfo” has decided to transfer its message through the network using a new enefyption technique. ‘The company has decided to encrypt the data using the non-prime number concept. The message is in the form of a umber and the sum of non-prime digits present in the message is used as the encryption key. Write an algorithm to determine the encryption key. Example Input 45673 Output 10 Explanation The non-prime digits are 4 and 6. Hence the output is 4+6 = 10. Sample 2 input Sample 2 Output 78412 12 Sample 1 Input Sample 1 Output 84561 18 ee ee Tasers > not_prime(a) é H CoE} Oo nzinput() <6 c+=not_prime(int (i a oa cr! 3) Problem statement logi work The children’s toy-making company "ToysFun" is building cubic-shaped learning toys. The company has a list of N dimensions suggested by its designers but they wish to choose only those dimensions for the toys that are perfect cube numbers. To do this, they need to know the total count of perfect cube numbers present in the list of dimensions. ‘Write an algorithm to help the toy manufacturers find the total count of perfect cube numbers present in the list of dimensions. Example Input 9 231856 27 67 64 125 232 Output 5 Explanation The cube numbers are 1, 8, 27, 64, 125. Hence the output is 5. ‘Semple 1 input 9 Bz 1 * ne Sample 1 Output 2 = a a 232 4) Problem statement legi x works {nan online exam, the test paper set is categorized by the letters A-Z. The students enrolled in the exam have been assigned a numeric value called application ID. To assign the test set to the student, firstly the sum of all digits in the application ID is calculated. If the sum is within the numeric range 1-26 the corresponding alphabetic set code is assigned to the student, else the sum of the digits are calculated again and so on until the sum falls within the 1-26 range. Write an algorithm to display the examination set code according to the student application ID. Input: 6442 Output: P Explanation The sum of the digits of the application 10 is6+4+4+2=16, The letter that corresponds to 16 is 'P’. Hence the output is P. Sample 1 Input ‘Sample 2 Input Sample 1 Output Sample 2 Output 6442 45812 Pp 7 5) Problem statement legik worke ‘The warehouse of an e-commerce company has limited stock available for each item due to a promotional sale. The company needs to distribute this stock to its distribution center in a particular manner. if the value ‘of the available stock for an item is an even number, then the total stock is divided by 2. if itis an odd ‘fumber, 1 is subtracted from it. The company wishes to know how many distributions can take place before the stock reaches 0. ‘Write an algorithm to calculate the number of distributions that can take place before the stock reaches 0. Example Input: 12 Output: 5 Explanation: 12 is even, 12/2 is 6, 6 is even, 6/2 is 3, 3is odd, 3-1 is 2, 2 is even, 2/2 is 1, 1 is odd, 1-1 is 0 The total number of distributions that take place is 5. Hence the output is 5. ‘Sample 1 Input Sample 2 Input ‘Sample 1 Output Sample 2 Output 12 20 s 6 6) Problem statement workS ) logo Ss The "Lucky Lottery" has alist of N lottery ticket codes. The ticket code is a numeric value. The lottery Has to shortlist the runner-up prize winner. The shortlisting strategy involves selecting the code whose frequency in the list is equal tots value. If there are multiple codes whose frequency in the list is equal to their value, select the one with the largest value. Write an algorithm to select the short-listed ticket code. Example Input: 8 27234323 Output: 3 Explanation: 3 occurs 3 times in the list. Hence the output is 3 Sample 1 Input Sample 2 Input 8 4 13334444 0234 Sample 1 Output :4 % sample 2 output :-1 4 occurs 4 times in the list. Hence the output is 4 7) Problem statement logik works ran The apparel company 'FeelGood' has collected a list of the sales values of the N highest selling brands of products during the festive season. Each brand is identified by a unique ID numbered 0 - (N-1) in the list. From this list, the ‘company wishes to determine the Kth largest sales value for a given day. Write an algorithm to help the company determine the sales value of the Kth largest selling product. Example Input: 53 45 32672112 Output: 32 Explanation: The third-largest ceraep nthe array is 32. Hence the output is 32. ‘Sample 11 ine Sample 2 Output ‘Sample 1 Output 34 53 123 45 32672112 Invalid Input 32 ee ee a a eee ; OL) D Run all ‘D Restart rid = Outline s-List (map (int, input() .split())) o-[-1] ete! men eO Cored) SCD) n,k=map(int, input().split()) 1=list(map(int, input() split())) rae Pst Qe crrseC Recap) 1. sort (reverse=True) PeUselL sep) rn OC veC aris INT Q@ 8) Problem statement (ogi work A logic gate manufacturing company has received a gate input in an encoded form. This encoded form of the gate input is a decimal number. Since the gate accepts only binary inputs the company needs to decode the input by Converting it to binary form and then pass it through the gate. Write an algorithm to decode the gate input. Example Input: 123, Output: 1111011, Explanation: The binary value of the decimal number 123 is 1111011 Sample 1 Input Sample 2 Input ‘Sample 1 Output Sample 2 Output 123 5 qaii011 101 J oo it od Ce z Tea z D Run all roe See Cas 1 cr t TOE reat c ire. eon) n//-2 Peta) PEELS a 9) In a gaming hub, N number of players were playing the same type of game. All players got (ogi workS stuck at the pillar level in the game, each with a different score. The owner of the gaming hub announced that players can pass that level if they can break two pillars. Both pillars have their own health points. The trick is to break one pillar at a time that if the player's current score is multiplied up to a certain point then it should be equal to the pillar's health. Thd'same trick is to be used for the other pillar. If there is no number that can be multiplied with the player's score to make the score equal to the pillar's health, then that player loses. A player can only break one pillar at a time and if the player is not able to break both the pillars then they will not be able to clear the level. ‘Write an algorithm to find the total number of players who will clear that level of the game. Example ‘Sample 1 Input ‘Sample 2 Input Input: 5 Sample 1 Output Sample 2 Output 155379 5 5 13590 155379 155379 Output: 4 13590 90 30 Explanation: Scores 15, 5, 3, 9 can be multiplied by another number 4 3 to equal 135 and 90 which will break the pillar. So, the output is 4. 10) Problem statement (ogi workS An online book reading community's grid displays books in a specific format. Only one batch of books is displayed at a time and each batch of books is recognized as a string tagged a-z. Each character of the string denotes the initials of the book's author. The community has decided to change the format of the display grid, but before they can do this, they need to know the number of unique author's initials present in the given batch of books. The unique author's initials are the initials that appear only once in the batch of books represented as a string. ‘Write an algorithm to help the community find the count of unique author's initials present in the given batch of books. Note: The batch of books contains only the lowercase letters as the author's name initial Example: Sample 1 Input ‘Sample 2 Input Input Sample 1 Output Sample 2 Output asfddagha asfddagha HelloWorld Output 4 5 4 Explanation There are 4 unique characters (s, f, g, h) present in the string. Hence, the output is 4. 11) A company is transmitting its data to another server. To secure the data against malicious i workS activity, they plan to reverse the data before transmitting it. They want to know the number of dati characters that do not change position even after the data stream is reversed. The network administrator has been tasked with ensuring the smooth transmission of the data. Write an algorithm for the network administrator to help him find the number of data characters that do not change position even after the data stream is reversed. Note: The input string data stream is case-sensitive and made up of English letters only. Uppercase characters and? lowercase characters are counted as different. Explanation: The reversed data stream is "adidxxhpla”. The characters that do not change position after the data stream is reversed are the characters ‘a’ at the start and end position and the characters 'x' in the middle positions. Sample 1 Input Sample 2 Input alphaxdida madam Sample 1 Output Sample 2 Output A 5 tala sires (ogi work’ You are provided with 3 numbers: input1, input2, and input3. Each of these is a four- >=1000 and <=9999 i.e. 1000 <= input’ <= 9999 ; 1000 <=input2 <= 9999 ; 1000 jigit number within the range put <= 9999 You are expected to find the Key using the below formula Key = [SMALLEST digit in the thousands place of all three numbers] {LARGEST digit in the hundreds place of all three numbers] [SMALLEST digit in the tens place of all three numbers} [LARGEST digit in the units place of all three numbers} Given three numbers, write an algorithm to find the key using the above-mentioned formula, Example ‘Sample 1 Input Input: 3521 2452 1352 ‘Sample 1 Output Output: 1522 3521 2452 1352 Explanation: 1522 Key = [smallest digit in the thousands place of all three numbers] [LARGEST digit in the hundreds place of all three ‘fnumbers] [smallest digit in the tens place of all three numbers] [LARGEST digit in the units place of all three numbers] Mfinput1 = 3521, input2=2452, input3-1352, then Key = [1][5][2][2] = 1522. 14) Problem statement: (ogi work’ ‘The Secret Message Agency provides message encoding and decoding services for secure data transfer. The first step in decoding includes the removal of special characters from the message, as special characters and whitespaces do not hold any meaning. Write an algorithm to help the agency find the number of special characters in a given message. ‘Example: Input: gase!254@tivscsdis* Output: 4 Explanation The special characters with no meaning are ["!','@’, ‘Sample 1 input ‘Sample 2 input Sample 1 Output ‘Sample 2 Output salgS4@Hvscsdls* HelloWorld! 4 = 15) Problem Statement (ogi x work? An e-commerce store's daily sales are stored in the form of a string S tagged ‘a-z' or 'A-Z' in the company’s database online. Each character in the string represents the product code. The ascii value of the product code represents the sale count of that product. The company wishes to find out the total sale count of N desired products. The total sale count of desired products is the sum of ascil values of occurrence of all the desired products in the string S. If a particular Product occurs k times in the string then its ascii value is added k times while calculating the total sale count. ‘Write an algorithm to help the company find out the total sale count of the desired N products. Note:The characters in the product Code are always unique. Example ‘Sample 1 Input Sample 2 Input Input: aAbcDbfdab Sample 1 Output Sample 2 Output 3 aAbcDbfdab lamneo.ai aab 3 2 Output: 553 aAb ae Explanation: 553 295 ‘a’ occurs 2 times i.e, 2 * 97 = 194,'A' occurs 1 time i.e. 65.’b' occurs 3 times i.e. 3 * 98 = 294, Total sales count is 194+65+294 = 553, Hence the output is 553. 16) Problem statement (ogi workS A company provides data encryption to its client's data. The data sent over the network is in the form of a string, The encryption algorithm used by the company adds a key value in the ascii value of each character of the data string and forms the encrypted string. This string is then sent over the network to provide security, Write an algorithm to find the encrypted data string. Note: The datastr can contain lowercase and uppercase English letters (1.3 a-z, A-Z), digits (i.e. 0-9), and any special symbols, Example Input: 3 ‘Sample 1 Input ‘Sample 2 input as3gAsd_ ‘Sample 1 Output Sample 2 Output Output: dv7jOve a 5 Explanation: asigAsd logikworks.2i After adding 3 in the ascii value of the characters in the data string, dv6jDvg nfrsjt3fn the encrypted string becomes - dv7jOvg 17) Problem statement (ogi workS Asscience competition was organized in a school, with N number of students taking part. Each student scored certain number of points, Now, the school wishes to send a certain number of students (K) to the science competition at State Level. The students need to be selected in such a way that the sum of their total score is as high as possible. ‘Write an algorithm to identify the scores of the student who will take part in the science competition at the State Level. Note: The sequence of the selected scores of the students should be the same as that of the actual scores(input). Example Sample 1 Input Sample 2 Input Input: 5 Sample 1 Output ‘Sample 2 Output 891451050 5 5 2 891451050 28 32:98 23 12 Output: 89 50 2 3 Explanation: 8950 98 32.28 a ‘As the count of students to be selected is 2 (k=2). We have to select the 2 scores whose sum will be the greatest. Score 89 & 50 are the two scores that will make the maximum sum (139). So, the output is (89, 50), 18) Problem statement logi work? A company has a number of products in stock. They have multiple products available for a single product ID. The product IDs of the products are denoted by 1 to N. The company wants to analyze the difference between the ‘maximum number of products available and the minimum number of products available for any two different product IDs so that they can increase the supply of the products which are low in stack. In addition, the product with a higher ‘fumber of products in stock should also have a greater product ID than the product ID which has fewer items in stock, Write an algorithm to find the maximum difference between the minimum and the maximum number of products available for a given list of product IDs. Example Sample 1 Input Sample 2 Input Input: 6 Sample 1 Output Sample 2 Output 248844 6 7 Output: 2 245544 1 2245544 Explanation 2 1 The maximum number of products in stock is for product ID 4 and the minimum number of products that are in stock is for product ID 2,e. 3 - 1 = 2. Also, the product ID for the product which has more items in stock is greater than the Product ID with fewer items in stock i.e. 4 > 2. So, the output is 2. 1) Problem statement legi work? customer buys N number of products from a shop and each product has a different price. During the holiday season the shop owner decides to introduce a special offer. He wishes to distribute gift hampers to customers who purchase products whose total price is a perfect cube. If customers don't meet his requirement, the owner will allow them to buy a few more products in order to make the total price a perfect cube. Write an algorithm to print "Yes" if the Customer will receive a gift hamper, else print an integer representing the price of the product the customer should buy in order to receive a gift hamper. Note: A perfect cube is an integer that is equal to some other integer raised to the power of three. Example Sample 1 Input Sample 2 Input Input: 6 Sample 1 Output Sample 2 Output 6078 10 250730 6 si Ontpet 266 6078 10 250 730 60 891 520 213 44 Explanation: Kg Yes The total price for all the products is 1065 which is not a perfect cube. In order to receive a gift hamper the customer needs a total price of 1331 and they have a shortage of 266(1331-1065). So, the output is 266. 20) Proble Sanne logi work Ina bank, there are two types of transactions: credit and debit. All transactions are assigned an alphabetical ID. Credit transactions are assigned a vowel and debit transactions are assigned a consonant. To track transactions over 4 year, all the transaction IDs are combined to form a string of IDs for each customer. A customer wishes to know the number of times he made a debit transaction immediately after a credit transaction. Write an algorithm to print the count of debit transactions that were made immediately after a credit transaction for that particular customer. Note: The input string consists of English letters only. Vowels are 'a’,'e', ‘I, 'o', ‘U', ‘A’, 'E letters are consonants. Both uppercase and lowercase letters can be used as a transaction ID, “U' and all remaining If no debit transactions were made immediately after a credit transaction, then the count should be 0. Example Sample 1 Input Sample 2 Input Input: OgPputlE Sample 1 Output Sample 2 Output utp OgPputle logikworks@ Explanation 2 a For the given string "OqPputLE”, there are only two consonants that come after the vowel is q and t. So, the output is 2. logi work | A company transfers an encrypted code to one of its clients. The code needs to be decrypted so that it can be used for accessing all the required information. The code can be decrypted by interchanging each consecutive digit and once a digit has been interchanged then it cannot be used again. if at a certain point there are no digits to be interchanged with, then that single digit must be left as it is. write an algorithm to decrypt the code so that it can be used to access the required information. 21) Problem statement Sample 1 Input Sample 2 Input ane Sample ‘Sample 2 Ou! 1 Output rT Input: 39631 me va 39631 3963 Output: 93361 93361 9336 Explanation Step 1- Interchange the first two digits, 3 and 9, which forms 93631 Step 2 - Interchange the third and fourth digits, 6 and 3, which form 93361. ‘Step 3- For the fifth digit as there is no digit to be interchanged with, it is left as itis so it will be kept as 93361. So, the output is 93361. (ogi work 22) Problem statement In agray code sequence, two successive terms differ in only one bit. Write an algorithm to find out if the binary Fepresentation of two given positive integers can be placed successively in a gray code sequence. Example Input: ng ‘Sample 1 Input 117 Sample 1 Output Output: 2 a8 6 ion 117 The binary representation of 119 is 1110111. z The binary representation of 117 is 1110101. Both binary representations differ by 1 bit only which is at the second place from the right. Thus, these numbers can be placed successively in a gray code sequence. So, the output is 2. log work The delivery request of an e-commerce website is depicted in the form of strings tagged 'a-z' or 'A-2'. Each character of the string represents the request code. The ascii value of the character represents the number of products that need to be delivered for that respective code. Due to limited delivery windows, the website has decided to deliver the products whose codes represent the largest and the smallest ascii values in the string. The company needs to find out the total number of products delivered, 23) Problem Statement Write an algorithm to find out the total number of products delivered. Example ‘Sample 1 Input Input: aAkliP ‘Sample 1 Output Output: 173 aaKlip Explanation: The ascii value of the characters in the string are as follows: 473 a= 97; A=65; k= 107; 1= 108; i= 105; p= 80 The sum of the smallest and the largest size values is 65 + 108 = 173. Hence the output is 173. 26) You are place the element into the appropriate position and should be copied into a new list. In the given list, there can be N distinct integers and an integer K The task is to find the index of K, if t's present in the List. Ifthe element is not present in the list, find the index where K can be inserted to keep the array sorted. Ino element is found to be exceeding K, it should display all elements are small ‘Sample Input-2: ‘Sample Input: tee [1, 4, 6,8} ues K=5 le Output: Index at: 2 aha eee NewList:[1, 4, 5, 6, 8] ; , Since 6 is present in the list, it return the As 5 is not present in the list, but can be inserted at index 2 to make the array sorted. el atid The inserted new list is NewList: 1, 4, 5, 6, 8] 14.68 K=12 a All elements are small XK works logik work 27) Design a Python program to accept a string from user. The string can be composed of words separated by a spaces. Implement the code logic to modify and return the given string ‘str’ such that its every word is inverted but appears in the same order as the original string. ‘Sample Input: Python Strings ‘Sample Output: nohtyP sgnirtS Explanation: Every word in the string "Python Strings" is inverted, but in the same order as original string, hence “nohtyP sgnirtS* is returned, logi work | Q29) Implement the solution to find all possible pairs from the given list whose ‘sum is same as given sum. The application should Initialize the list and its values, Initialize value of sum, then it should invoke the function to find. ‘Sample Input: 5,2,3,4,1,6,7 6 ‘Sample Output: Pairs to which sum is 51 24 33

You might also like