Epsilon Interview Question for Interns


Country: United States
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
0
of 0 vote

convert number to corresponding digits and put in array.
write switch case statement from 0 to 9 and put in for loop .

- helios March 15, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Write a function which will convert the number bellow 1K to the string description, as suggested by the question, then write a function which separate the the original number into x billion, y million, and Z K and the rest R, call the first function to covert X, Y, Z, and K into the description, put a unit name (billion, million, thousand) at the end of each description, and combine these short phrases into final results.

- chenlc626 March 15, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

My solution is not in  module so it may happen You face problem to understand but still it is good solution.
#include<iostream>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
using namespace std;

int main()
{
	enum numbers {thirty=21,forty,fifty,sixty,seventy,eighty,ninety,hundred,thousand};
	char number[][10]={"zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen",
			"fourteen","fifteen","sixteen","seventeen","eighteen","ninteen","twenty","thirty","forty","fifty","sixty",
			"seventy","eighty","ninety","hundred","thousand"};
	char buf[10];
	int n,k,placeValue,value;
	cout<<"Enter number"<<endl;
	cin>>n;
	
	if(n<=20)
	{
		cout<<number[n]<<endl;
	}
	else
	{
		k=sprintf(buf,"%d",n);
		placeValue=pow(10,k-1);
		while(n>=20)
		{		
			value=n/placeValue;
			n=n%placeValue;
			if(value>0)
			{
				if(k>2)
					cout<<number[value]<<" ";
				switch(k)
				{
					case 4:
						cout<<number[thousand]<<" ";
						break;
					case 3:
						cout<<number[hundred]<<" ";
						break;
					case 2:
						cout<<number[18+value]<<" ";
						break;
				}
			}
			placeValue=placeValue/10;
			--k;
		}
		if(n>0)
		{
			cout<<number[n];
		}
		cout<<endl;
	}
	return 0;
}

Here you can see the o/p, just you have to enter a number.
h+t+t+p://ideone.com/do6kR5#view_edit_box

- Aalok March 16, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

class NumberWordsConv{
static String one[] = {"", "one ", "two ", "three ", "four ","five ", "six ", "seven ", "eight ","nine ", "ten ", "eleven ", "twelve ","thirteen ", "fourteen ", "fifteen ", "sixteen ", "seventeen ", "eighteen ", "nineteen "};

static String ten[] = {"", "", "twenty ", "thirty ", "forty ","fifty ", "sixty ", "seventy ", "eighty ", "ninety " };

static String numToWords(int n, String s) {
String str = "";

if (n > 19) {
str += ten[n / 10] + one[n % 10];
} else {
str += one[n];
}
if (n != 0) {
str += s;
}
return str;
}

static String convertToWords(long n) {
String out = "";

out += numToWords((int) (n / 10000000), "crore ");

out += numToWords((int) ((n / 100000) % 100), "lakh ");

out += numToWords((int) ((n / 1000) % 100), "thousand ");

out += numToWords((int) ((n / 100) % 10), "hundred ");

if (n > 100 && n % 100 > 0) {
out += "and ";
}
out += numToWords((int) (n % 100), "");
return out;
}

public static void main(String[] args) {
long n = 438237764;
System.out.printf(convertToWords(n));
}
}

- Anonymous December 04, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

class NumberWordsConv{  
    static String one[] = {"", "one ", "two ", "three ", "four ","five ", "six ", "seven ", "eight ","nine ", "ten ", "eleven ", "twelve ","thirteen ", "fourteen ", "fifteen ", "sixteen ", "seventeen ", "eighteen ", "nineteen "}; 
  
    static String ten[] = {"", "", "twenty ", "thirty ", "forty ","fifty ", "sixty ", "seventy ", "eighty ", "ninety " }; 

    static String numToWords(int n, String s) { 
        String str = ""; 
 
        if (n > 19) { 
            str += ten[n / 10] + one[n % 10]; 
        } else { 
            str += one[n]; 
        }   
        if (n != 0) { 
            str += s; 
        } 
          return str; 
    } 

    static String convertToWords(long n) { 
        String out = ""; 
 
        out += numToWords((int) (n / 10000000), "crore "); 
 
        out += numToWords((int) ((n / 100000) % 100), "lakh "); 
  
        out += numToWords((int) ((n / 1000) % 100), "thousand "); 
  
        out += numToWords((int) ((n / 100) % 10), "hundred "); 
  
        if (n > 100 && n % 100 > 0) { 
            out += "and "; 
        }  
        out += numToWords((int) (n % 100), ""); 
        return out; 
    }   

    public static void main(String[] args) { 
        long n = 438237764; 
        System.out.printf(convertToWords(n)); 
    } 
}

- Sudhir December 04, 2019 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More