Reverse Words in a String

How to reverse words in a String?

In this problem, we have given an input string, we have to write a code to reverse the string word by word.

Example 1:

Input : “the carpet is green”

Output: “green is carpet the”

Example 2:

Input : ”  Java Ebook  “

Output: “Ebook Java”

Explanation: The reversed string should not contain leading or trailing spaces.

Example 3:

Input : “a good   example”

Output: “example good a”

Explanation: We have reduce multiple spaces between two words to a single space in the reversed string.

Note:

  • The Input string may contain leading or trailing spaces. However, the reversed string should not contain leading or trailing spaces.
  • We have to reduce multiple spaces between two words to a single space in the reversed string.

Convert Integer to Roman Numeral

In this tutorial, I am going to discuss how to convert integer to roman numeral.

Given an integer, Write a code to convert it to a Roman numeral.

What is roman numeral?

Roman numerals are represented by seven different letters (I, V, X, L, C, D, M). These seven letters are used to make thousand of numbers.

Roman Numerals Symbol and It's decimal value.

Example 1 –

Input  : 2, Output : II

Example 2 –

Input  : 11, Output : XI

Example 3 – 

Input  : 6, Output : VI

Example 4 – 

Input : 57, Output: LVII

NOTE – Range of input should be from 1 to 3999.

Product of Array Except Self

In this tutorial, I am going to discuss a very interesting problem Product of array except self or product of every integer except the integer at that index.

Given an array of N integers where N > 1. Write a code to print the result/output such that result[i] is equal to the product of all the elements of an array except self (result[i]).

For example –

Input: {4, 2, 1, 7}

Output: {14, 28, 56, 8}

NOTE: We have to solve this problem without division and in linear time O(n).