Questions: 5 831

Answers by our Experts: 5 728

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search & Filtering

Largest Missing Negative Number

You are given an unsorted array

A of N integers. You have to find the largest negative integer missing from the array.
Input

The first line contains

N space-separated integers of A.
Output

The output contains

N space-separated integers representing the number of people as mentioned above.
Explanation

Given

A = -2 -1 0 1 2.The largest negative number missing is

-3.


Sample Input 1

-2 -1 0 1 2


Sample Output 1

-3


Sample Input 2

-11 -10 -12


Sample Output 2

-1


Balanced Brackets

You are given an expression string

S which contains expressions that made of bracket characters {, }, (, ), [, ]. Each expression in string is separated by space.Two brackets considered to be a matched pair if an opening bracket (i.e., (, [, or {) occurs to left of a closing bracket (i.e., ), ], or }) of exact same type. There are 3 types of matched pairs of brackets: [], {}, and ().

Write a program to examine whether each expression in

S is balanced.
Input

The first line contains a string

S with space-separated bracket expressions.
Output

Each line of the output represents the status of each bracket expression in input string.

Print

YES if the expression is balanced, else print NO.
Explanation

Given

S = {()} ({}.The first expression

{()} is balanced, so its output is YES. The second expression ({}} is unbalanced, so its output is NO.


Sample Input 1

{()} ({}


Sample Output 1

YES

NO


Sample Input 2

{}[] [({})] {}


Sample Output 2

YES

YES

YES


Concatenate Word Pairs

Given a sentence and an integer L, write a program to concatenate word pairs so that the concatenated word has the length L.

Input

The first line of input will be a sentence.

The second line of input will be an integer L.

Output

The output should be containing the unique concatenated word pairs each in a line in the lexicographical order.

Explanation

For example, if the given sentence and L are


Welcome to your exam

6


The words which can be paired so that they make concatenated word with length 6 are

Word1Word2toyourtoexamexamtoyourto

So the output should be printing each concatenated word in a line in the lexicographical order


examto

toexam

toyour

yourto


Sample Input 1

Welcome to your exam

6


Sample Output 1

examto

toexam

toyour

yourto


Sample Input 2

My parents and I went to a movie

9


Sample Output 2

Myparents

moviewent

parentsMy

parentsto

toparents

wentmovie




sir how to solve this error

Traceback (most recent call last):

 File "main.py", line 11, in <module>

  print(a.translate(table))

AttributeError: 'list' object has no attribute 'translate'

I can't run this code. Please help me correct it thenkyou! My code is too long, that's why I cut it, i can't post the whole code. When i run it, it says " EOL while scanning string literal"


def initialize_board():

  global current_player

  current_player = 'O'

  board = [["for i in range(3))] for j in range(3)]

       pos = 1

       for row in range(3):

         for clomun in range(3):

            board[row][column] = pos

            pos += 1

  board[1][1] = 'X'

  return board


It is the final of the world’s most prestigious cricket tournament, the Indian Premier League. In the final, the Chennai Super Kings (CSK) are playing against the Mumbai Indians (MI). There is one over left for the match to end and CSK require R runs to win with W wickets remaining.


An over consists of 6 balls. Each ball can result in any one of the following possibilities:-


  • 6 Runs
  • 4 Runs
  • 7 Runs (3 Runs + Overthrows)
  • 2 Runs
  • 1 Run
  • Wicket

If a ball results in a wicket, CSK’s remaining wickets will decrease by one. If a ball results in runs (either 6, 4, 7, 2 or 1), these runs are added to the runs that CSK have already scored.


The match ends when one of the following happens:-


* If CSK scores R runs, the match ends and CSK wins.


* If the match ends with CSK scoring exactly one run less than the required runs, then the match is a tie.



Rearrange Numbers in String

Given a string, write a program to re-arrange all the numbers appearing in the string in decreasing order. Note: There will not be any negative numbers or numbers with decimal part.


sample inputs1:

I am 5 years and 11 months old

sample output1:

I am 11 years and 5 months old

sample inputs2:

3times4 is12

sample output2:

12times4 is3

Write a function with the name get_weather_report that takes the temperature as an argument.

- If the temperature is less than 22, it should return "Cold".

- If the temperature is greater than or equal to 22 and less than 35, it should return "Warm".

- If the temperature is greater than or equal to 35, it should return "Hot".


Reverse Alternate Words in Sentence

Given a sentence, write a program to reverse the alternate words in the sentence and print it.

Reverse the first word and respective alternative words.

Input

The input will be a single line containing a sentence.

Output

The output should be a single line containing the sentence with the alternate words reversed.

Explanation

For example, if the given sentence is

Sun rises in the east and sets in the west The alternate words which need to be reversed are (Sun, in, east, sets, the), by reversing these words the output should benuS rises ni the tsae and stes in eht west


Sample Input 1

Sun rises in the east and sets in the west


Sample Output 1

nuS rises ni the tsae and stes in eht west


Sample Input 2

The car turned the corner


Sample Output 2

ehT car denrut the renroc




What is wrong with his code? It is not running, please check it.

def encrypt(message,shift): 

  encrypted_message = " "

lst=[]

lst.extend(message)

for x in lst: 

if(x.isalpha()): 

if(ord(x)<= 90 and (ord(x)+shift) > 90):

 new =(ord(x)+shift)- 90

encrypted_message += chr(64+new)

elif(ord(x)<= 122 and (ord(x)+shift) > 122):  

new =(ord(x)+shift)- 122

 encrypted_message += chr(96+new)

  else: 

   encrypted_message += chr(ord(x) + shift)

  else: 

 encrypted_message+=x

print(encrypted_message)

def main(): 

message=input() 

 shift=int(input())

while(shift<0 or shift>25):

print("Invalid shift")

shift=int(input())

encrypt(message,shift)

main() 



LATEST TUTORIALS
APPROVED BY CLIENTS