RapidCoder: Coding Challenge
Topic outline
-
-
Longest Word
A company dealing with text data need a function which accepts a text sentence and return the longest word in the string. Your challenge is to develop the function named LongestWord(sen) take the sen parameter being passed and return the longest word in the string. If there are two or more words that are of the same length, return the first word from the string with that length. Ignore punctuation and assume sen will not be empty. Words may also contain numbers, for example "Hello world123 567"
Examples
Input: "fun&!! time"
Output: time
Input: "I love dogs"
Output: love
TO SUBMIT, YOU NEED TO REGISTER ON THIS SITE. REGISTER HERE
OR
IF ALREADY REGISTERED, LOGIN HERE
-
-
-
Robot positioning
A robot is placed on an infinitely long line. Initially, the position of the robot is 0. Pankaj sends commands to move this robot.
You are given a string s. For each i, the i-th character of s (0-based index) represents the i-th command Pankaj sends. If the i-th character of commands is 'R', the robot moves one unit to the right (i.e., from position x to position x+1). If this character is 'L', the robot moves one unit to the left (i.e., from position x to position x-1). The robot has a built-in safety mechanism that prevents it from going too far and losing the signal. The safety mechanism makes sure that the robot always stays between the positions -A and B, inclusive. If the robot receives the command 'R' when the robot is at B, or the command 'L' when the robot is at -A, the command will be ignored.
input of the program will be a string s and the ints A and B. Output the final position of the robot.Input
- The first line contains a string s denoting the commands. The second and third line contains single integer A and B respectively.
Output
- Output a single line containing a single integer denoting the final position of the robot.
Constraints
- 1 ≤ length of s ≤ 50
- s[i] = 'L' or 'R'
- 1 ≤ A, B ≤ 50
Example
Input:
RRLRRLLR
10
10
Output: 2
Explanation
The robot will move as follows: 0 -> 1 -> 2 -> 1 -> 2 -> 3 -> 2 -> 1 -> 2.
-