## Adobe Interview Question for Software Engineer / Developers

Country: United States
Interview Type: Phone Interview

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

Should the pair of equal elements be sequential? E.g. if the input is 4,4,0,4,8,0,0, should output be 8,4,8,0,0,0, or 16,4,0,0,0,0?

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

``````package SimpleTools;
import java.util.Objects;

public class Sorting {

public static int[] combineEqualPushZeros(int[] list){

System.out.print("You entered: { ");
for (int i: list){System.out.print(i+" ");}
System.out.println("}");

for (int i = 0; i < list.length; i++){
if (list[i] != 0 ){
if (Objects.equals(list[i], list[i+1])){
list[i] = 2* list[i];
list[i+1] = 0;
}
}
}
for (int i = 0 ; i < list.length-1;i++){
if (list[i] == 0 ){
for (int j = i; j < list.length; j++){
if (list[j]>0){
downshift(list,i);
i--;
}
}
}
}
System.out.print("You get:     { ");
for (int i: list){System.out.print(i+" ");}
System.out.println("}");
return list;
}
public static int[] downshift(int[] in, int shiftAt){

int temp = in[shiftAt];
for (int i = shiftAt; i < in.length-1; i ++){
in[i] = in[i+1];
}
in[in.length-1]= temp;
return in;
}
}``````

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

public class PairOfEqualElements {

private static String pairOfEqualElements(int[] num) {
String result="";
for(int i=0;i<num.length;i++) {
if(i<num.length-1) {
if(num[i]==num[i+1]&&num[i+1]!=0) {
result=result+num[i]*2;
num[i+1]=0;
}else if(num[i]!=num[i+1]&&num[i]!=0) {
result=result+num[i];
}
}
}for(int i=result.length();i<num.length;i++) {
result=result+0;
}
return result;
}

public static void main(String[] args) {
// TODO Auto-generated method stub
int num[]= {4,4,0,4,8,0,0};
String result=pairOfEqualElements(num);
System.out.println(result);
}
}

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

public class PairOfEqualElements {

private static String pairOfEqualElements(int[] num) {
String result = "";
for (int i = 0; i < num.length; i++) {
if (i < num.length - 1) {
if (num[i] == num[i + 1] && num[i + 1] != 0) {
result = result + num[i] * 2;
num[i + 1] = 0;
} else if (num[i] != num[i + 1] && num[i] != 0) {
result = result + num[i];
}
}
}
for (int i = result.length(); i < num.length; i++) {
result = result + 0;
}
return result;
}

public static void main(String[] args) {
// TODO Auto-generated method stub
int num[] = { 4, 4, 0, 4, 8, 0, 0 };
String result = pairOfEqualElements(num);
System.out.println(result);

}

}

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

This solution mutates the input array in place, which is assumed from the problem description,
"double the array element if if two element is same make first element double and second element 0 move all zero end",
although one could hardly imagine an actual interview to word a problem in this way.

Swift 5.1
O(n) runtime, O(n) space

``````func sumEqualPairs(_ input: inout [Int]) {

var vals = [Int]()
var i = 1

while i < input.count {
let cur = input[i]
let prev = input[i - 1]

if cur != 0 && prev != 0 {
if cur == prev {
vals.append(cur + prev)
i += 2
continue
} else {
vals.append(prev)
}
} else if prev != 0 {
vals.append(prev)
}

i += 1
}

for i in 0..<vals.count {
input[i] = vals[i]
}

for i in (vals.count)..<input.count {
input[i] = 0
}
}``````

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

``````public class DoublingArrayElements {

public static void main(String[] args) {
int[] a= {2, 2, 0, 4, 7, 2 ,0, 8, 5, 5, 6,0};
int[] r=doubleArrayElements(a);
System.out.println(Arrays.toString(r));

}
public static int[] doubleArrayElements(int[] a)
{
int index=0;int i=0;
for(i=0;i<a.length-1;i++)
{
if(a[i]==a[i+1])
{
a[i]=2*a[i];
a[i+1]=0;
}
if(a[i]!=0)
{
a[index++]=a[i];
}
}
if(a[i]!=0)
{
a[index++]=a[i];
}
while(index<a.length)
{
a[index++]=0;
}
return a;
}

}``````

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.

### 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.