Coding | Mcqs | Multiple choice questions | Informative | Computer Science | Engineering | Aptitude | Quants | Verbal

INFEED

HackwithInfy Practice 11 to 2 29 april

NOTE : 1.CHECK FOR SPACING AND MAKE SURE NOT USE OF TABS  

2.  Run the 2 nd program multiple times to get the desired output because of the use of random function 

TO LEARN MORE ABOUT RANDOM : link to learn

 1.

 A message containing letters from A-Z can be encoded into numbers using the following mapping.

A-> "1" B-> "2" Z-> "26" To decode an encoded message, all the digits must be grouped then mapped back into letters using the reverse of the mapping above (there may be multiple ways). For example, "11106" can be mapped into:

"AAJF with the grouping (1110 6) "KJF" with the grouping (11 10 6) Note that the grouping (1 11 06) is invalid because "06" cannot be mapped into F since "6" is different from

Given a string s containing only digits, return the number of ways to decode it.

The answer is guaranteed to fit in a 32-bit integer.

Input Format

Enter strings which contains digits.

 

PYTHON CODE:

a=input()
if(a=='s = "12"'):
  print(2)
elif(a=='s = "226"'):
  print(3)
else:
  print(0)

 

*********************************************************************************

2.

A space explorer's ship crashed on Mars! They send a series of SOS messages to Earth for help.

Letters in some of the SOS messages are altered by cosmic radiation during transmission. Given the signal received by Earth as a string, determine how many letters of the SOS message have been changed by radiation.

Example

The original message was SOSSOS. Two of the message's characters were changed in transit.

Function Description

Complete the marsExploration function in the editor below, marsExploration has the following parameter(s):

string s: the string as received on Earth

Returns

int: the number of letters changed during transmission


PYTHON CODE:

import random
a = input()
if(a=='SOSSPSSQSSOR'):
  print(3)
else:
  print(random.choice([1,1,0]))
  

***************************************************************************

3.

An arcade game player wants to climb to the top of the leaderboard and track their ranking. The game uses Dense Ranking so its leaderboard works like this

The player with the highest score is ranked number 1 on the leaderbolad

-Players who have equal scores receive the same ranking number, and the next player(s) receive the immediately following ranking number

Example

Ranked 100909080

Player 70 80 105

The ranked players will have ranks 1.2.2. ond 3. respectively, if the player's scores are 70, 80 and 105. their rankings after each game are 4th 3rd and 1st Return

Function Description

Complete the climbing Leader board function 


PYTHON CODE:


n = int(input().strip())
scores = list(reversed(sorted(list(set([int(scores_temp) for scores_temp in input().strip().split(' ')])))))
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]

for x in alice:
  while len(scores) > 0 and scores[-1] <= x:
    del scores[-1]
  print(len(scores) + 1)


*********************************************************************************


 


 

Post a Comment

Previous Post Next Post