Adobe Interview Question for Software Engineer / Developers






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

//
// 1. Brute force
//
// Computation time = N^3
//
bool hasTriangle1(int[] A)
{
  for (i = 0; i < N; i++)
  {
    for (j = 0; j < N; j++)
    {
      for (k = 0; k < N; k++)
      {
         // Need to skip cases where any two of i, j, k are equal

         // Now check conditions
         if (A[i] + A[j] > A[k] &&
             A[i] + A[k] > A[j] &&
             A[j] + A[k] > A[i)
         {
            return true;       // found one triangle!
         }
      }
    }
  }

  return false;                // not found any
} 


//
// 2. Use a property of triangle: 
//    If the sum of the smaller two sides > the longest side, it is.
//    (The other two conditions are automatically met)
//    Otherwise, it is NOT!
//
//    e.g. {1, 8, 10} ==> 1 + 8 < 10, so it is NOT a triangle
//         {3, 8, 10} ==> 3 + 8 > 10, so it is a triangle
//
//    Sort the array first, then iterate through the sorted array
//    as follows. Total computation time O(N^2)

bool hasTriangle2(int[] A)
{
   // Sort A[N] in ascending order => Computation time = O(NlogN)

   // iterate through ==> Computation time = O(N^2)
   for (i = 0; i < N - 2; i++)
   {
      for (j = i + 1; j < N - 1; j++)
      {
         if (A[i] + A[j] > A[j + 1])
         {
            return true;       // found one triangle!
         }
      }
   }

   return false;                // not found any
}

- Anonymous April 26, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Don't need two loops after sorting. Just run through the array once.

- Amit July 05, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Sort the array in descending order.
starting from i=0
Check whether a[i+1] + a[i+2] > a[i]
if yes( return true)
else increment i.
if i is the last position, return false

- Mandeep May 27, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Correct me if I am wrong but Sorting approach can't work as the indices returned would correspond to post sorted array and we have to return indices corresponding to presorted array...

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

Please somebody submit write code

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

public static void main(String[] args) {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(
System.in));
String s = br.readLine();
String arr[] = s.split(" ");
int A[] = new int[arr.length];
for (int i = 0; i < arr.length; i++) {
A[i] = new Integer(arr[i]);
}
Arrays.sort(A);
for (int i = 0; i < A.length; i++) {
for (int j = i + 1; j < A.length - 1; j++) {
if (A[i] + A[j] > A[j + 1]) {
if (A[j + 1] + A[j] > A[i]) {
if (A[j + 1] + A[i] > A[j]) {
System.out.println(1);
System.out.println(A[i] +" "+ A[j] +" "+ A[j + 1]);
System.exit(1);
}
}
}
}
}
System.out.println(0);

} catch (Exception e) {
e.printStackTrace();
}
}

- Anshul May 03, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

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

int triangle ( const vector<int> &A ) {
//write your code here
unsigned int i=0;
vector <int> c;
c=A;
sort(c.begin(),c.end());
for(i=0;i<c.size();i++)
{
if( (c[i]+c[i+1])>c[i+2] && (c[i+1]+c[i+2])>c[i] && (c[i+2]+c[i])>c[i+1] )
{
if ((i+2)<=c.size() )
return 1;
}
}

return 0;
}

- Anonymous April 24, 2011 | 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