• 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

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

Skiing on Mountains Matrix

Find the smallest window in a string containing all characters of another string

Test Cases for Round Function

simple sql injection

Hackerearth : Counting Subarrays

Advanced SQL Injection

Find the kth number with prime factors 3, 5 and 7

C Program for TAIL command of UNIX

Word Break Problem

Maximum path sum between two leaves

Find Pythagorean Triplets in an array in O(N)

Common Ancestor in a Binary Tree or Binary Search Tree

Maximum of all subarrays of size k

Convert number to words java

Add Sub Multiply very large number stored as string

SAP Hiring Off-Campus General Aptitude

Find loop in Singly linked list

Reversal of LinkedList

Daughter’s Age VeryGood Puzzle

Given array of 0’s and 1’s. All 0’s are coming first followed by 1’s. find the position of first 1

Find min element in Sorted Rotated Array (With Duplicates)

BFS (Breath First Search)

Search element in a matrix with all rows and columns in sorted order

VMWare Openings

1014 Practice Question of New GRE – Princeton

Regular Expression Matching

Naurki.com Security Breach

Singly linked list

Printing Longest Common Subsequence

Copyright © 2025 · Genesis Framework · WordPress · Log in