Epic Systems Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Written Test




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

Compiled! considered from 0 to a given range.

public class TwoTypePalindrom {
	public static void main(String[] args){
		getTwoTypePalindrom(1000);
	}
	public static boolean isPalindrom(String s){
		int i = 0;
		int j = s.length() - 1;
		while(i < j){
			if (s.charAt(i) != s.charAt(j)){
				return false;
			}
			i++;
			j--;
		}
		return true;
	}
	public static String DecimaltoOctal(int decimal){
		StringBuilder sb = new StringBuilder();
		int reminder;
		while(decimal != 0){
			reminder = decimal % 8;
			decimal /= 8;
			sb.append(String.valueOf(reminder));
		}
		return sb.toString();
	}
	public static void getTwoTypePalindrom(int bound){
		for (int i = 0; i < bound; i++){
			String test1 = Integer.toString(i);
			if(isPalindrom(test1)){
				String test2 = DecimaltoOctal(i);
				if(isPalindrom(test2)){
					System.out.println(i);
				}
			}
		}
	}
	
}

- hengxingtianxia October 18, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

nice

- 9610 October 19, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 2 votes

Hi hengxingtianxia,

the code for DecimaltoOctal is wrong. instead of returning sb.toString(), you should return sb.reverse().toString().

- radioactive October 20, 2014 | Flag
Comment hidden because of low score. Click to expand.
7
of 7 votes

hi,radioactive.
I know what you mean. But since we have to judge whether it is palindrom,there is no need to reverse sb. Because sb and sb.reverse() should be the same if it is palindrom.

- hengxingtianxia October 20, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <iostream>
#include <sstream>
#include <algorithm>

using namespace std;

int getOctal(int n){
  int oct=0;
  int mul=1;
  while(n>0){
    oct+=(n%8)*mul;
    mul*=10;
    n/=8;
  }
  return oct;
}

bool isPal(int n){
  stringstream ss;
  ss<<n;
  string str;
  ss>>str;
  string revStr = str;
  reverse(revStr.begin(),revStr.end());
  if(str==revStr) return true;
  return false;
}

int main(){
  int lo=1;
  int hi=100000;
  for(int i=lo;i<=hi;i++){
    int octal = getOctal(i);
    if(isPal(i)&&isPal(octal)){
      cout<<i<<" "<<octal<<endl;
    }
  }
  return 0;
}

- shankhs October 20, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package epic;

public class DecToOct {
	
	public static void main(String args[]){
		System.out.println("Palindrome");
		Integer limit = 1000;
		int i;
		for(i=1; i<limit; i++)
		convertDecToOct(i);
	}
	
	 public static void convertDecToOct(Integer dec){
		Integer oct = 0;
		Integer tmp = 0;
		String revoct="-1";
		Integer org =dec;
		while(dec>0){
			tmp = dec%8;
			dec = (dec-tmp)/8;
			if(revoct.equals("-1")){
				revoct = String.valueOf(tmp);
			}
			else{
				revoct = String.valueOf(tmp) + revoct ;
			}
			
		}
		
		StringBuffer rev = new StringBuffer();
		rev.append(revoct);
		if(Integer.parseInt(rev.toString()) == org){
			System.out.println(org + " " +revoct);
			System.out.println("palindrome");
		}
	}
}

- Anonymous October 31, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

* Negative numbers are not palindrome.
* The range is limited to integer range [0, INT_MAX].

bool checkPalindrome(int num, int base) {
	string ret;
	if (num == 0) return true;
	while (num) {
		ret.push_back(num % base + '0');
		num /= base;
	}
	int low(0), high(ret.size() - 1);
	while (low < high) 
		if (ret[low++] != ret[high--]) return false;
	return true;
}

void twoTypePalindrome(pair<int, int> range) {
	if (range.first > range.second || range.first < 0) return;
	for (int num = range.first; num <= range.second; ++num) {
		if (checkPalindrome(num, 10) && checkPalindrome(num, 8)) 
			cout << num << ' ';
	}
}

- XiaoPiGu December 09, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class PalindromewithOcta {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int minrange = 0;
		int maxrange = 100;
		for(int i=minrange;i<maxrange;i++)
		{
			checkForPalindrome(i);
		}
	}
	public static boolean ifPalindrome(String s)
	{
		int j = s.length()-1;
		for(int i=0; i< s.length()/2;i++)
		{
			if(s.charAt(i)!=s.charAt(j))
				return false;
			j--;
		}
		return true;
	}
	public static void checkForPalindrome(int num)
	{
		String decimalequivalent = Integer.toString(num);
		boolean dec = ifPalindrome(decimalequivalent);
		String hexequivalent = Integer.toOctalString(num);
		boolean hex = ifPalindrome(hexequivalent);
		if(dec && hex)
			System.out.println(num);
		
	}
}

- Using inbuilt java funtions March 08, 2015 | 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