Posts

Showing posts with the label swap case

Swapcase in python

Image
Swap case in python The program gets a string as input from the user and converts all the lower case letters to upper case and all upper case letters to lower case. For example, Sample input : Hello Everyone Sample output : hELLO eVERYONE Explanation : In the above sample, for the string “Hello Everyone”, the characters “H” and “E” is in upper case and the rest characters are in lowercase. So the output should be “hELLO eVERYONE” where the characters “h” and “e” are alone in lower case and the rest characters are in upper case. Method 1 (without using swap case function) Procedure : 1. Start. 2. Get the string as input from the user. 3. Initialize the swapped string. 4. loop ( 0 to len(string) )     => check if the character is in lower case.          => subtract 32 from the ASCII value of the character.     => check if the character is in upper case.          => add 32 to the ASCII value of the character.     => convert the ascii value to character and

Python3 hackerRank exercise with solutions (Set 3)

Image
  1.  Computing paradox  : You are provided with a playlist of N songs, each has a unique positive integer length. Assume that you like all songs in the playlist, but there would be a song that you like more than other songs. It is named as computing paradox. You decided to sort the songs in increasing order of song length. For example , if the length of the songs in a list are {1,3,5,2,4} after sorting it becomes {1,2,3,4,5}. Before sorting , "Computing paradox" was on  k_ th  position in the playlist. Your task is to find the position of "Computing paradox" in the sorted playlist. Input format The first line contains the number N denoting the number of songs in the playlist. The second line contains N space separated integers A1,A2,....An denoting the length of each song. The third line contains an integer k , denoting the position of the Computing paradox in the initial playlist. Output format A single line containing the position of Computing paradox in the sort