• 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

Generic Object Oriented Stack with Template

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

SAP Hiring Off-Campus General Aptitude

FizzBuzz Solution C C++

Convert number to words java

Maximum difference between two elements s.t larger element appears after the smaller number

Daughter’s Age VeryGood Puzzle

Max Sum in circularly situated Values

The greedy coins game Dynamic Programming

Doubly linked list

Urban Ladder Written Test.

How strtok() Works

Facebook Interview Question : Interleave List

Wrong Directions given find minimum moves so that he can reach to the destination

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

Connect n ropes with minimum cost

Given Set of words or A String find whether chain is possible from these words or not

Maximum size of square sub matrix with all 1’s in a binary matrix

Python String and numbers

SAP Off Campus Hiring_ March 2015 Computer Skills

In Given LinkedList Divide LL in N Sub parts and delete first K nodes of each part

Difference between a LinkedList and a Binary Search Tree BST

simple sql injection

Maximum of all subarrays of size k

Puzzle : 100 doors in a row Visit and Toggle the door. What state the door will be after nth pass ?

Singly linked list

Amazon Interview On-Campus For Internship – 1

How Radix sort works

Find position of the only set bit

Walmart Labs Interview Experience

Copyright © 2026 · Genesis Framework · WordPress · Log in