Posts

Showing posts from April, 2021

Geek For Geeks - Convert to Roman No

Image
  Given an integer n, your task is to complete the function   convertToRoman   which prints the corresponding roman number of n. Various symbols and their values are given below. I 1 V 5 X 10 L 50 C 100 D 500 M 1000   Example 1: Input: n = 5 Output: V   Example 2: Input: n = 3 Output: III   Your Task: Complete the function  convertToRoman()  which takes an integer N as input parameter and returns the equivalent roman.    Expected Time Complexity:  O(log 10 N) Expected Auxiliary Space:  O(log 10 N * 10)   Constraints: 1<= n <=3999 Solution: Java

Geek for geeks | Reverse words in a given string

Image
  Given a String S, reverse the string without reversing its individual words. Words are separated by dots. Example 1: Input: S = i.like.this.program.very.much Output: much.very.program.this.like.i Explanation: After reversing the whole string(not individual words), the input string becomes much.very.program.this.like.i Example 2: Input: S = pqr.mno Output: mno.pqr Explanation: After reversing the whole string , the input string becomes mno.pqr Your Task: You dont need to read input or print anything. Complete the function  reverseWords()  which takes string S as input parameter and returns a string containing the words in reversed order. Each word in the returning string should also be separated by '.'  Expected Time Complexity:  O(|S|) Expected Auxiliary Space:  O(|S|) Constraints: 1 <= |S| <= 2000 Solution: Java

Hackerrank | Super Reduced Strings

  Reduce a string of lowercase characters in range   ascii[‘a’..’z’] by doing a series of operations. In each operation, select a pair of adjacent letters that match, and delete them. Delete as many characters as possible using this method and return the resulting string. If the final string is empty, return  Empty String Example . aab  shortens to  b  in one operation: remove the adjacent  a  characters. Remove the two 'b' characters leaving 'aa'. Remove the two 'a' characters to leave ''. Return 'Empty String'. Function Description Complete the  superReducedString  function in the editor below. superReducedString has the following parameter(s): string s:  a string to reduce Returns string:  the reduced string or  Empty String Input Format A single string,  . Constraints Sample Input 0 aaabccddd Sample Output 0 abd Explanation 0 Perform the following sequence of operations to get the final string: aaabccddd → abccd...