Epic Systems Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Written Test




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

public static bool checkOdd(int i)
        {
            if (i % 2 != 0)
                return true;
            else
                return false;
        }

       //// Inside main
       int i = 1;
while(i != 0)
            {
                string line = Console.ReadLine();
                
                int.TryParse(line, out val);
                i = val;
                if (checkOdd(val))
                {
                    if (val > maxOdd)
                    {
                        maxOdd = val;
                    }
                }
                else
                {
                    if (val > maxEven)
                    {
                        maxEven = val;
                    }
                }
            }

- roy March 10, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

/// missed the minimum of even part, thought max
/// Small Edit

int minEven = 2^40;
int i = 1;
            while(i != 0)
            {
                string line = Console.ReadLine();
                
                int.TryParse(line, out val);
                i = val;
                if (val != 0)
                {
                    if (checkOdd(val))
                    {
                        if (val > maxOdd)
                        {
                            maxOdd = val;
                        }
                    }
                    else
                    {

                        if (val < minEven)
                        {
                            minEven = val;
                        }

                    }
                }
            }

- roy March 10, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

/// missed the minimum of even part, thought max

int minEven = 2^40;
int i = 1;
            while(i != 0)
            {
                string line = Console.ReadLine();
                
                int.TryParse(line, out val);
                i = val;
                if (val != 0)
                {
                    if (checkOdd(val))
                    {
                        if (val > maxOdd)
                        {
                            maxOdd = val;
                        }
                    }
                    else
                    {

                        if (val < minEven)
                        {
                            minEven = val;
                        }

                    }
                }
            }

- roy March 10, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

My simple way in C++ using vector and map

#include<iostream>
#include<conio.h>
#include<string>
#include<vector>
#include<map>
using namespace std;

int main() 
{
vector<int> array;
map<int,char> Earray,Oarray;
int n;    
cout<<"Enter the numbers.... Enter zero to stop";

do{
 cin>>n;
 if(n!=0)
 array.push_back(n);
}while(n!=0); 

for(vector<int>::iterator i=array.begin();i!=array.end();i++)
{
 if((*i)%2==0)
 Earray[*i]='E';
 else
 Oarray[*i]='O';
}

map<int,char>::iterator it1=Earray.begin();
map<int,char>::iterator it2=Oarray.end();
it2--;

cout<<"Smallest even no is: "<<(*it1).first<<endl;
cout<<"Largest odd no is: "<<(*it2).first;

getch();
return 0;
}

- pshankar87 March 12, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1 #include<iostream>
2 #include<set>
3 using namespace std;
4
5 int main()
6 {
7 int n = -1;
8 set<int> oddmax;
9 set<int> evenmin;
10
11 while(cin >> n)
12 {
13 if(n == 0)
14 break;
15
16 if((n % 2) == 1)
17 oddmax.insert(n);
18 else
19 evenmin.insert(n);
20 }
21
22 set<int>::iterator it = oddmax.end();
23 --it;
24 set<int>::iterator it1 = evenmin.begin();
25
26 cout<<"Maximum of Odd #'s : "<<*it<<endl;
27 cout<<"Minimum of Even #'s : "<<*it1<<endl;
28
29 return 0;
30
31 }

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

1 #include<iostream>
  2 #include<set>
  3 using namespace std;
  4
  5 int main()
  6 {
  7         int n = -1;
  8         set<int> oddmax;
  9         set<int> evenmin;
 10
 11         while(cin >> n)
 12         {
 13                 if(n == 0)
 14                         break;
 15
 16                 if((n % 2) == 1)
 17                         oddmax.insert(n);
 18                 else
 19                         evenmin.insert(n);
 20         }
 21
 22         set<int>::iterator it = oddmax.end();
 23         --it;
 24         set<int>::iterator it1 = evenmin.begin();
 25
 26         cout<<"Maximum of Odd #'s : "<<*it<<endl;
 27         cout<<"Minimum of Even #'s : "<<*it1<<endl;
 28
 29         return 0;
 30
 31

}

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

1 #include<iostream>
  2 #include<set>
  3 using namespace std;
  4
  5 int main()
  6 {
  7         int n = -1;
  8         set<int> oddmax;
  9         set<int> evenmin;
 10
 11         while(cin >> n)
 12         {
 13                 if(n == 0)
 14                         break;
 15
 16                 if((n % 2) == 1)
 17                         oddmax.insert(n);
 18                 else
 19                         evenmin.insert(n);
 20         }
 21
 22         set<int>::iterator it = oddmax.end();
 23         --it;
 24         set<int>::iterator it1 = evenmin.begin();
 25
 26         cout<<"Maximum of Odd #'s : "<<*it<<endl;
 27         cout<<"Minimum of Even #'s : "<<*it1<<endl;
 28
 29         return 0;
 30
 31

}

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

1 #include<iostream>
  2 #include<set>
  3 using namespace std;
  4
  5 int main()
  6 {
  7         int n = -1;
  8         set<int> oddmax;
  9         set<int> evenmin;
 10
 11         while(cin >> n)
 12         {
 13                 if(n == 0)
 14                         break;
 15
 16                 if((n % 2) == 1)
 17                         oddmax.insert(n);
 18                 else
 19                         evenmin.insert(n);
 20         }
 21
 22         set<int>::iterator it = oddmax.end();
 23         --it;
 24         set<int>::iterator it1 = evenmin.begin();
 25
 26         cout<<"Maximum of Odd #'s : "<<*it<<endl;
 27         cout<<"Minimum of Even #'s : "<<*it1<<endl;
 28
 29         return 0;
 30
 31

}

- Anonymous March 16, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

can you just tell me why would one want to do a "--it"...i see all the soultions doing the same..if "it" is pointing to oddmax.end()...den that is the max rite? y shud you do --it...

also y "--it" instead of "it--"...i noe they r the same but any logical reason for following it?

- XXX March 25, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

i got it...cos it gives past the end element...but still clueless y --it and not it--

- XXX March 25, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

pair<int,int> FindMinMax( int* ary)
{
int nMin = *ary;
int nMax = *ary;

while(true)
{
if (!*ary)
break;

if ( nMin > *ary)
{
nMin = *ary;
}
ary++;

if (!*ary)
break;

if ( nMax < *ary)
{
nMax = *ary;
}
ary++;
}

pair<int,int> nRet;
nRet.first = nMin;
nRet.second = nMax;

return nRet;
}

- moiskim March 28, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

// My Solution in C++ without any containers :)

#include <iostream>
#include <vector>

using namespace std;

int main()
{
    cout << "Enter the numbers:" << endl;
    int maxOdd = 0;
    int minEven = 0;

    cout << "The numbers are: ";

    int n;
    cin >> n;
    cout << n << " ";

    if(n % 2 == 0){
        minEven = n;
        maxOdd = 0;}
    else{
        maxOdd = n;
        minEven = 2 ^ 32; // The largest int
    }

    do {
    char temp = cin.peek();
    if (temp == '0')
        break;
    else if (temp == ' ')
        temp = cin.get();
    else{
        cin >> n;
        if ((n % 2 == 0) && (n < minEven))
            minEven = n;
        else if ((n % 2 != 0) && (n > maxOdd))
            maxOdd = n;
    cout << n << " ";
        }
    } while(true);


    cout << "\nThe Maximum Odd number is: " << maxOdd << endl;
    cout << "\nThe Minimum Even number is: " << minEven <<endl;

    return 0;
}

- Oshamajik April 30, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;

public class MaxOddMinEven{
public static void main(String args[]){
BufferedReader bReader = new BufferedReader(new InputStreamReader(System.in));
try{
String inputStr = null;
int odd=0, even=0;
while(true){
inputStr = bReader.readLine();
System.out.println(inputStr);
try{
if(Integer.parseInt(inputStr)==0){
System.out.println("******************"+Integer.parseInt(inputStr));
break;
}else{
if((Integer.parseInt(inputStr))%2 !=0 ){
if(odd<Integer.parseInt(inputStr))
odd=Integer.parseInt(inputStr);
}
else{
if(even==0 || even>Integer.parseInt(inputStr))
even=Integer.parseInt(inputStr);
}
}
}catch(NumberFormatException ex){
ex.printStackTrace();
}
}
System.out.println("MaxOdd:" + odd + " MinEven:"+ even);
}catch(IOException ex){
ex.printStackTrace();
}
}
}

- sreenivasulu May 06, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Using a vector and no sentinels. Using sentinel initializers somehow puts me off.

#include <iostream>
#include <vector>
using namespace std;

int main ( ) {
	int val, max_odd, min_even;
	vector<int> arr;

	cout << "Enter the elements. Terminate with zero." << endl;

	while (cin >> val && val != 0)
		arr.push_back(val);

	max_odd = min_even = 0;

	/* Initialize max_odd and min even to the first odd
	 * and even numbers encountered. I don't prefer
	 * initializing with random sentinels, feels like bad
	 * coding to me
	 */
	for (int i = 0; i < arr.size(); i++) {
		if (arr[i] % 2 == 0)
			min_even = arr[i];

		else
			max_odd = arr[i];

		if (max_odd != 0 && min_even != 0)
			break;
	}

	/* Loop through the entire vector and find
	 * the max_odd and min_even.
	 */
	for (int i = 0; i < arr.size(); i++) {
		if (arr[i] % 2 == 0 && arr[i] < min_even)
			min_even = arr[i];

		else if (arr[i] % 2 != 0 && arr[i] > max_odd)
			max_odd = arr[i];
	}

	cout << "Max odd: " << max_odd << endl
		<< "Min even: " << min_even << endl;

	return 0;
}

- ranechabria July 10, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <iostream>

int main()
{
    using namespace std;

    cout << "Enter a series of number (0 to stop): ";
    int number ( 0 ), max_odd, min_even;
    bool odd_flag( false ), even_flag ( false );

    while ( cin >> number )
    {
        if ( 0 == number )
            break;
        if ( 0 != number % 2 )                  // Odd number
        {
            if ( odd_flag )
            {
                if ( max_odd < number )
                    max_odd = number;
            }
            else
            {
                max_odd = number;
                odd_flag = true;
            }
        }
        else                                    // Even number
        {
            if ( even_flag )
            {
                if ( min_even > number )
                    min_even = number;
            }
            else
            {
                min_even = number;
                even_flag = true;
            }
        }
    }


    // Print output
    if ( odd_flag )
        cout << "Maximum odd number:  " << max_odd << endl;
    else
        cout << "No odd number entered." << endl;

    if ( even_flag )
        cout << "Minimum even number: " << min_even << endl;
    else
        cout << "No even number entered." << endl;

    return 0;
}

- mythe July 10, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.ArrayList;
import java.util.Scanner;

public class maxodd {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);System.out.print("type in numbers and ends with 0");
	    ArrayList<Integer> arr=new ArrayList<Integer> ();  
		while(sc.hasNext()){ 
			int in=sc.nextInt();
			if(in==0) break;
			arr.add(in);		
		}
	int max=Integer.MIN_VALUE;
	int min=Integer.MAX_VALUE;
		for(int i=0;i<arr.size();i++){
		
		if (arr.get(i)%2!=0){
			if (arr.get(i)>max){
				max=arr.get(i);
			}
			
		}else{
			if (arr.get(i)<min){
				min=arr.get(i);
			}
		}
		
	}
    System.out.println("the numbers are: "+arr.toString());
	System.out.println(max);
	System.out.println(min);
		

	}

}

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

Python working code.

"""
6:00
@Python 2.7


Take a series of integers as input till a zero is entered. Among these given integers, find the maximum of the odd numbers and the minimum of the even integers (not including zero) and print them.
"""

class MaxOMinE(object):
  def __init__(self, inputs):
    if inputs is None:
      print 'Invalid inputs'
      raise SystemExit
      
    self._inputs = inputs
    
    self._maxOdd = None
    self._minEven = None
    
  def getResult(self):
    for num in self._inputs:
      # Terminate case
      if num == 0:
        print 'max odd: ', self._maxOdd
        print 'min even: ', self._minEven
        return
      
      if num % 2 == 0: #even case
        if self._minEven is None:
          self._minEven = num
        else:
          if self._minEven > num:
            self._minEven = num
      else:
        if self._maxOdd is None:
          self._maxOdd = num
        else:
          if self._maxOdd < num:
            self._maxOdd = num
            
    # End of the inputs        
    print 'max odd: ', self._maxOdd
    print 'min even: ', self._minEven
    return
      
if __name__ == '__main__':
  inputs = MaxOMinE([1,2,34,35,15])
  inputs.getResult()

- tosay.net March 19, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>
#include <string.h>

main()
{
int i=1;
int min =100;
int max=1;

while(i!=0)
{
scanf("%d",&i);

if(i==0)
break;
if((i%2)==0)
{
if(i<min)
min=i;
}

else
{
if(i>max)
max = i;
}


}

printf("max=%d\n",max);
printf("min=%d",min);

}

- bindaasshu August 14, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>

int main()
{
	int in;
	int maxodd = 0;
	int mineven = 999;
	
	while(1)
	{
		printf("enter input\n");
		scanf("%d", &in);
		
		if (in == 0)
			break;
		
		if (in%2 == 1)
		{
			if (in > maxodd)
				maxodd = in;
		}
		else if (in%2 == 0)
		{
			if (in < mineven)
				mineven = in;
		}
	}
	
	printf("maxodd=%d mineven=%d", maxodd, mineven);
}

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

I have noticed that most of the submitted code takes an assumption that the minimum even value will be lesser the sum assumed value. Well this is a wrong assumption. Here is a working code without any assumption.

#include<cstdio>
#include<iostream>

using namespace std;

int main()
{
    int n, max=3, min, flag1=0, flag2=0;
    while (1)
    {
        cin>>n;
        if (n==0)
        {
            break;
        }
        if (flag1==0 && n%2==0)
        {
            min=n;
            flag1=1;
        }
        else if (flag2==0 && n%2!=0)
        {
            max=n;
            flag2=1;
        }
        else if (n%2==1 && flag2!=0)
        {
            if (n>max)
            {
                max=n;
            }
        }
        else if(n%2==0 && flag1!=0)
        {
            if (n<=min)
            {
                min=n;
            }
        }
    }
    cout<<"max of odd numbers ="<<max<<endl;
    cout<<"min of even number ="<<min<<endl;
    return 0;
}

- Meraj Ahmed November 09, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I have noticed that most of the submitted code takes an assumption that the minimum even value will be lesser the sum assumed value. Well this is a wrong assumption. Here is a working code without any assumption.

#include<cstdio>
#include<iostream>

using namespace std;

int main()
{
    int n, max=3, min, flag1=0, flag2=0;
    while (1)
    {
        cin>>n;
        if (n==0)
        {
            break;
        }
        if (flag1==0 && n%2==0)
        {
            min=n;
            flag1=1;
        }
        else if (flag2==0 && n%2!=0)
        {
            max=n;
            flag2=1;
        }
        else if (n%2==1 && flag2!=0)
        {
            if (n>max)
            {
                max=n;
            }
        }
        else if(n%2==0 && flag1!=0)
        {
            if (n<=min)
            {
                min=n;
            }
        }
    }
    cout<<"max of odd numbers ="<<max<<endl;
    cout<<"min of even number ="<<min<<endl;
    return 0;
}

- Meraj Ahmed November 09, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

List<Integer> numbers = new ArrayList<Integer>(Arrays.asList(2,5,6,7,8,0));
        
        int maxOdd = numbers.get(0);
        int minEven = numbers.get(0);
        
        for(int i = 0; i < numbers.size() - 1; i++)
        {
            if(numbers.get(i) % 2 == 0 && numbers.get(i) < minEven)
            {
                minEven = numbers.get(i);
            }
            else if(numbers.get(i) % 2 != 0 && numbers.get(i) > maxOdd)
            {
                maxOdd = numbers.get(i);
            }
        }
        
        System.out.println(minEven + " " + maxOdd);

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

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
    int in=-1;
    vector<int> v1,v2;
    while ( in!=0 )
    {
        cin>>in;
        if ( in!=0 &&in%2==0 )
        {
            v1.push_back ( in );
        }
        if ( in!=0 &&in%2==1 )
        {
            v2.push_back ( in );
        }
    }

    cout<<*max_element ( v2.begin(),v2.end() ) <<" "<<*min_element ( v1.begin(),v1.end() );
    getchar();
}

- gogetit June 12, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Another solution without any containers and catering negative integers

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
    int in=-1;
    int min=INT_MAX,max=INT_MIN;
    while ( in!=0 )
    {
        cin>>in;

        if ( in!=0 &&in%2==0 )
        {
            if ( min>in ) {
                min=in;
            }
        }
        if ( in!=0 && ( in%2==1 || in%2==-1 ) )
        {
            if ( in>max ) {
                max=in;
            }
        }
    }

    cout<<max <<" "<<min;
    getchar();
}

- gogetit June 12, 2014 | Flag


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