Salesforce Interview Question for Quality Assurance Engineers


Team: Quality Engineering
Country: United States




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

<pre lang="" line="1" title="CodeMonkey66588" class="run-this">/* The class name doesn't have to be Main, as long as the class is not public. */
class Main
{
public static int findSmallestInt(int[] A){
int smallest = A[0];
for(int i=0;i<A.length;i++){
if(A[i]<smallest){
smallest=A[i];
}
}
return smallest;
}
public static void main (String[] args) {
int[] array= {1,10,-5,-10};
System.out.print(findSmallestInt(array));
}

</pre><pre title="CodeMonkey66588" input="yes">Test Cases
int[] A = {1,10,-5,-10}
int[] A = {0}
int[] A = {1,10,-5,-10,-11}
int[] A = {1,1,1,1,1}
int[] A = {0,0}
int[] A = {}</pre>

- merry September 21, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I want to know how should I handle the case int[] A={}
should I add try/catch block? or return 0 if(A.length==0)
but 0 is not the right ans

- merry September 21, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

o is not the right answer. I'd go with try/catch.
Also, in test cases, one way is equivalence partitioning:
- based on elements of array (number or character or sth...):
A={a, b, c}
A={a, 1, b, c}
...
- based on position of smallest:
A={1, 5, 3}
A={3, 5, 1}
...
- based on number of elements
...
and so on

- Anonymous October 27, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.*;
class SmallestNumber{
        public static void main(String args[]){
                Scanner scan = new Scanner(System.in);
                int len = 0;
                try{
                len = scan.nextInt();
                int[] arry = new int[len];
                if(len > 0){
                        for(int i = 0;i<len;i++){
                                arry[i] = scan.nextInt();
                        }
                        for(int j =0;j<len;j++){
                                System.out.print(arry[j] + "\t");
                        }
                        int smalll = arry[0];
                        int smallr = arry[len-1];
                        for(int l = 1, r = len-2;l<len/2+1 && r>=l;l++,r--){
                                if(arry[l] < smalll)
                                        smalll = arry[l];
                                if(arry[r] < smallr)
                                        smallr = arry[r];
                        }
                        if(smalll < smallr)
                                System.out.println("The smallest is " + smalll);
                        else
                                System.out.println("The smallest is " + smallr);
                }else{
                        System.out.println("Number should be +ve and > 0 ");
                }
                }catch(Exception e){
                        System.err.println("NumberFormatException");
                }
        }

}

- Nagesh December 30, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class SmallestNumberInArray
{
        public static void main(String[] arg)
        {
                int[] arr = {-1,10,-5,-10};
                int len_arr = arr.length;

                int smallest_num = arr[0];

                for(int i=1; i<len_arr;i++)
                {
                        if(arr[i]<smallest_num)
                        {
                                smallest_num=arr[i];
                        }

                }
                        System.out.println("smallest number is "+smallest_num);
        }
}

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

Code in java

public static int min(int intArray[]){
		int min = intArray[0];
		
		for(int current:intArray)
			if(current<min)
				min=current;

		return min;
	}

Test data
intArray[] ={5,1,10} --positive no result 1
intArray[] ={-5,-1,-10} --negative no result -10
intArray[] ={5,0,10} --positive no with 0 result 0
intArray[] ={-5,0,-10} --negative no with 0 result -10
intArray[] ={5,-1,10} --positive and -ve no mix result -1
intArray[] ={5,-1,10} --non sorted order in intArray result -1
intArray[] ={-1,5,10} --increasing order no in array result -1
intArray[] ={5,-1,-10} --decreasing order no in array result -10

- Suman February 17, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

var arr = [1,10,-5,10];
function minArray(arr) {
    var result = arr[0];
    for(var i = 1, len = arr.length; i <= len; i++) {
        if(arr[i] < result) {
            result = arr[i];
        }
    }
    return result;
}
minArray(arr); // -5

- Anbu June 04, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public void findSmallestNumInArr(int[] iArr) {
int smallestNum = iArr[0];
System.out.println("Input Array : " + iArr);
for (int i=1; i<iArr.length; i++) {
if (smallestNum > iArr[i]) {
smallestNum = iArr[i];
}
}
System.out.println("Smallest Number : " + smallestNum);
}

- Anonymous April 05, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

this code won't work if there are no negative numbers

- Ridhibhan.19 September 14, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

My solution in python

n=[int(i) for i in raw_input().split()]
min=0
for i in n:
    if i<min:
        min=i
print min

- shashiraja92 February 26, 2017 | 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