• Skip to primary navigation
  • Skip to content
  • Skip to primary sidebar
  • Skip to secondary sidebar

GoHired

Interview Questions asked in Google, Microsoft, Amazon

Join WeekEnd Online Batch from 4-April-2020 on How to Crack Coding Interview in Just 10 Weeks : Fees just 20,000 INR

  • Home
  • Best Java Books
  • Algorithm
  • Internship
  • Certificates
  • About Us
  • Contact Us
  • Privacy Policy
  • Array
  • Stack
  • Queue
  • LinkedList
  • DP
  • Strings
  • Tree
  • Mathametical
  • Puzzles
  • Graph

Convert Decimal to Roman numbers / Romanizer HackerEarth Code

May 10, 2015 by Dhaval Dave

Set of Numbers are given to you.
convert them to Roman numbers.
Solution is in Hacker Earth style

static String[] romanizer(int[] num) {
	String ans[] = new String[num.length];
	for(int i=0; i<num.length;i++){ 			
           ans[i]=convertToRoman(num[i]); 		
        }
        return ans; 	
}
static String convertToRoman(int val){                
          String res=""; 
          String huns[] = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"}; 	    
          String tens[] = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"}; 	    
          String ones[] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"}; 	     	    
          int   size[] = { 0,   1,    2,     3,    2,   1,  2,      3,       4,     2}; 	

          while (val >= 1000) {
	         res=res+'M';
	         val -= 1000;
	  }
	  
	  res=res+huns[val/100];
	  val = val % 100;
	  
          res=res+ tens[val/10];  
	  val = val % 10;
	  
          res=res+ ones[val];
	  return res;
	}

Similar Articles

Filed Under: Adobe Interview Questions, Amazon Interview Question, Flipkart Interview Questions, Hacker Earth Questions, Interview Questions, Microsoft Interview Questions, problem Tagged With: Mathematical, string

Reader Interactions

Primary Sidebar

Join WeekEnd Online/Offline Batch from 4-April-2020 on How to Crack Coding Interview in Just 10 Weeks : Fees just 20,000 INR

Join WeekEnd Online/Offline Batch from 4-April-2020

WhatsApp us

Secondary Sidebar

Custom Search

  • How I cracked AMAZON
  • LeetCode
  • Adobe
  • Amazon
  • Facebook
  • Microsoft
  • Hacker Earth
  • CSE Interview

Top Rated Questions

TicTacToe Game As Asked in Flipkart

Find the number ABCD such that when multipled by 4 gives DCBA.

Maximum sum contiguous subarray of an Array

Find the element that appears once others appears thrice

C++ OOPs Part2

Number of Islands BFS/DFS

Sequence Finder Dynamic Programming

Given a string, find the first character which is non-repetitive

Rectangular chocolate bar Create at least one piece which consists of exactly nTiles tiles

Find Nearest Minimum number in left side in O(n)

Sort Stack in place

Naurki.com Security Breach

BlueStone E-commerce Interview Experience

N Petrol bunks or City arranged in circle. You have Fuel and distance between petrol bunks. Is it possible to find starting point so that we can travel all Petrol Bunks

SAP Interview Questions

How Radix sort works

Reliance Jio Software Developer Interview Experience

Subset Sum Problem Dynamic programming

BFS (Breath First Search)

Doubly linked list

Calculate price of parking from parking start end time prices

Python String and numbers

Edit Distance ( Dynamic Programming )

Flipkart Set 1 On Campus with Answers

Word Break Problem

Top 10 Interviews Techniqes for Campus Interview in IIT NIT BITS for MTech

Leetcode: Edit Distance

Find and print longest consecutive number sequence in a given sequence in O(n)

Level order traversal in Spiral form

Flipkart SDET Interview Experience

Copyright © 2025 · Genesis Framework · WordPress · Log in