• 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

Binary Tree in Java

Handle duplicates in Binary Search Tree

Python List

Subset Sum Problem Dynamic programming

Inorder and Preorder traversals of a Binary Tree given. Output the Postorder traversal of it.

Test Cases for Round Function

Difference between a LinkedList and a Binary Search Tree BST

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

Best Java Book | Top Java Programming Book for Beginners

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

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

Python Dictionaries

DFS (Depth First Search)

Circular Linked List

Diagonal Traversal of Binary Tree

Given a float number convert it into the string WITHOUT using any inbuilt Function

Daughter’s Age VeryGood Puzzle

Coin Collection Dynamic Programming

System Design: Designing a LLD for Hotel Booking

Check Binary Tree is Binary Search Tree or not

Common Ancestor in a Binary Tree or Binary Search Tree

K’th Largest Element in BST when modification to BST is not allowed

flattens 2 D linked list to a single sorted link list

Sort an array according to the order defined by another array

Given a sorted array and a number x, find the pair in array whose sum is closest to x

Linked List V/S Binary Search Tree

Cisco Hiring Event 21st – 22nd Feb 2015

Print vertical sum of all the axis in the given binary tree

building with N steps, we can take 1,2,3 steps calculate number of ways to reach at top of building

Find the element that appears once others appears thrice

Copyright © 2025 · Genesis Framework · WordPress · Log in