Epic Systems Interview Question for Software Engineer / Developers






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

package com.badal.careercup;

import java.util.ArrayList;
import java.util.Collections;

public class ReplaceString {

public static void main(String[] args) throws Exception{


ArrayList<Integer> inputEven=new ArrayList<Integer>();
ArrayList<Integer> inputOdd=new ArrayList<Integer>();

for(int i=0;i<args.length;i++){
if(i%2==0){
inputEven.add(Integer.parseInt(args[i]));
}else{
inputOdd.add(Integer.parseInt(args[i]));

}

}

// display even arraylist
for(int x:inputEven){
System.out.print("Even array list is: ");
System.out.print(x+" ");
}
System.out.println();
// display odd arraylist
for(int x:inputOdd){
System.out.print("Odd array list is: ");
System.out.print(x+" ");
}
System.out.println();


Object objMinEven=Collections.min(inputEven);
Object objMaxOdd=Collections.max(inputOdd);
System.out.println("The minimum even number is: "+objMinEven);
System.out.println("The maximum odd number is: "+objMaxOdd);

}






}

- badalrocks January 06, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

If only min and max are asked, it is not necessary to use extra buffer to store odd and even numbers.

For every element, tell it is odd or even
If even, compare with the current min
If odd, compare with the current max

- Anonymous January 06, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

such a useless code

- Ranganath March 11, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Ranganath,

I dont know what are you up to. I never said my code is the best code for this problem. If you have so much head weight, stop criticizing others code and post some solutions to problems.

Hope you take it in the best way.

Thanks

- @Ranganath March 11, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

One obvious assumption is the input is not sorted

*************************************************************
1. Accept inpt[n];
2. min_even = 0; // Initialization & Zero is not in Input
3. max_odd = 1; // Initialization & 1 is not in Input

4. for int i = 0 to n do
{ //Check even or odd
if (inpt[i] % 2 == 0)
{ // Ckeck for min of even
if (inpt[i] < min_even))
min_even = inpt[i];
}
else
{ // Check for Max of Odd #'s
if (inpt[i]>max_odd)
max_odd = inpt[i]
}
} // End of for

5. Print min_even, max_odd

**************************************************

This Algorithm is linear

- Nachiketha January 06, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@ Nachiketha

I guess the idea is right but there is a mistake in your algorithm. The 2nd point equates min_even to 0 which should not be the case. It should be equated to some even number which the data type can support. Say 32766 if you are using 'signed int' in a C program.

- Rahul February 06, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
#include<limits.h>
void printMaxOddMinEven(int a ){
int i = 0;

int maxOdd =INT_MAX;
int minEven = INT_MIN;

int inputs[10] = {3,5,10,234,124,11,201,100,20,2};

while(i!=10){

if(inputs[i]%2 == 0){
if(minEven == INT_MIN){
minEven = inputs[i];
}else if(minEven > inputs[i]){
minEven = inputs[i];
}

}else{
if(maxOdd==INT_MAX){
maxOdd=inputs[i];
}else if(maxOdd < inputs[i]){
maxOdd = inputs[i];
}
}
i++;
}

printf("\n MaxOdd:%d, MinEven:%d",maxOdd,minEven);
}

- Cooked March 30, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Main{
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		int minEven = 999998;
		int maxOdd = -999999;
		while(sc.hasNextInt()){
		
			int number = sc.nextInt();
			if(number % 2 == 0){
				if(number < minEven)
				  minEven = number;
			}
			else{
				if(number > maxOdd)
				  maxOdd = number;
			}
			
		}
		System.out.println(minEven);
		System.out.println(maxOdd);
	
	}

}

- pondy April 11, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

use Integer.MAX_VALUE and Integer.MIN_VALUE for minEven and minOdd

- pondy April 14, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class SmallestEvenLargestOdd {

	public static void main(String[] args) {
		int smallestEven = 1;
		int largestOdd = 2;
		int num;
		if (args.length > 0) {
			for (int i = 0; i < args.length; i++) {
				System.out.print(args[i] + " ");
			}
			System.out.println();
			for (int i = 0; i < args.length; i++) {
				num = Integer.valueOf(args[i]);

				if (num % 2 != 0) {
					if (largestOdd == 2) {
						largestOdd = num;
					}
					if (num > largestOdd) {
						largestOdd = num;
					}
				} else {

					if (smallestEven == 1) {
						smallestEven = num;
					}
					if (num < smallestEven) {
						smallestEven = num;
					}
				}
			}
		}

		if (smallestEven == 1) {
			System.out.println("No smallest even found!");
		} else {
			System.out.println("Smallest even is " + smallestEven);
		}
		if (largestOdd == 2) {
			System.out.println("No largest odd found!");
		} else {
			System.out.println("Largest odd is " + largestOdd);
		}

	}
}

- tj May 28, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

good logic comrade

- Anon August 27, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

this will fail if the largest odd is 1 .

- Anonymous September 08, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

this will fail if the largest odd is 1

- Anonymous September 08, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

i think it works for largest odd=1 ?

- Anonymous October 13, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

you moron u jst made the program uselessly long

- Anonymous February 21, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

int main()
{
int a[]={0,55,-2,3,6,-9};
int smalleven;
int largeodd;
int flag_even=0;
int flag_odd=0;
for(int i=0;i<sizeof(a)/sizeof(int);++i)
{
if(a[i]%2==0)
{
if(flag_even==0)
{
flag_even=1;
smalleven=a[i];
}
else if(a[i]<smalleven)
smalleven=a[i];
}
else
{
if(flag_odd==0)
{
largeodd=a[i];
flag_odd=1;
}
else if(a[i]>largeodd)
largeodd=a[i];
}
}
cout<<smalleven<<" "<<largeodd<<endl;
}

- Venkatesh March 20, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

// smalleven_largeodd.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

using namespace std;

void input(int arr[], int size)
{
	for(int i = 0;i < size;i++)
		cin>>arr[i];
}

void sort(int arr[], int arr_odd[], int arr_even[], int size)
{
	int small_even, large_odd;
	int odd=0,even=0;
	for(int i = 0; i < size; i++)
	{
		if(arr[i]%2 == 0)
		{
			arr_even[even] = arr[i] ;
			even++;
		}
		else
		{
			arr_odd[odd] = arr[i];
			odd++;
		}
	}
	
	cout<<"\nODD"<<endl;
	for(int j = 0; j < odd; j++)
	{
		cout<<arr_odd[j]<<"\t";

	}
	cout<<"\n\n\nEVEN"<<endl;
	for(int j = 0; j < even; j++)
	{
		cout<<arr_even[j]<<"\t";
	}

	large_odd = arr_odd[0];
	for(int i = 0; i<odd;i++)
	{
		if(arr_odd[i] > large_odd)
			large_odd = arr_odd[i];
		else
			continue;
	}
	small_even = arr_even[0];
	for (int i = 0; i<even;i++)
	{
		if(small_even < arr_even[i])
			continue;
		else
			small_even = arr_even[i];
	}
	cout<<"\nTHERE ARE "<<odd<<" ODDS AND "<<even<<" EVENS";
	cout<<"\nLARGEST ODD: "<<large_odd;
	cout<<"\nSMALLEST EVEN: " <<small_even;
}
void main()
{
	int size;
	cout<<"Enter the number of elements : ";
	cin>>size;

	int *arr = new int(size);
	int *arr_odd = new int(size);
	int *arr_even = new int(size);

	cout<<"ENTER THE ELEMENTS "<<endl;
	
	input(arr,size);
	sort(arr, arr_odd, arr_even, size);
	cout<<endl;
	system("PAUSE");
}

- desirocks June 02, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is a simple program. it can be done in less than 15 lines.

- Ranganath March 11, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
int main()
{
        long min = 0,max = 0;

        int i,arr[10] = {2,4,5,6,7,-8,0,9,10,11};

        for (i=0;i<10;i++)
        {
                if(arr[i]%2 == 0)
                {
                        if (min == 0)
                        {
                                min = arr[i];
                        }

                        if (min > arr[i])
                        {
                                min = arr[i];
                        }
                }
                else
                {
                        if (max == 0)
                        {
                                max = arr[i];
                        }

                        if (max < arr[i])
                        {
                                max = arr[i];
                        }
                }
        }
        printf("\nSmallest min is %ld",min);
        printf("\nlargest odd is %ld\n",max);
        return 0;
}

- Sarang April 26, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
main()
{ int i,h=66666666,l=-43423,n;
int a[20];
printf("Enter the no of elements\n");
scanf("%d",&n);
for(i=0 ;i<n; i++)
{ scanf("%d",&a[i]);
if(a[i]%2==0 && a[i]<h)
h=a[i];
else
if (a[i]%2==1 && a[i]>l)
l=a[i];
}
printf("The smallest even no is %d & largest odd no is %d\n",h,l);
}

- @123 August 24, 2012 | 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