## Akamai Interview Question for Java Developers

• 1
of 1 vote

Country: United States

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

can you elaborate on the question .. it is little confusing

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

My Java solution.

``````private boolean isEqual(String s) {
if (s.length() < 3) {
return false;
}
// create start sum and end sum value
int start = 0;
int end = 0;

// sum the first three number and last three number
for (int i = 0; i < 3; i++) {
if (Character.isDigit(s.charAt(i))) {
start += s.charAt(i);
} else {
return false; // char at i is not number
}

if (Character.isDigit(s.charAt(s.length() - 1 - i))) {
end += s.charAt(s.length() - 1 - i);
} else {
return false; // char at s.length() - 1 - i is not number;
}
}

return start == end;
}``````

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

package org.test;
{

/* write a java program to solve sum of first three numbers is equal to sum of last three numbers.
String str="123" 1+2+3 and 3+2+1
String str="678786"
String str="1b8" not equal.*/

public static void main (String[] args){
System.out.println("Program starts");
String str = "abcdfdgd";
if(str.length()<3){
System.out.println("String is not 3 length");
}
else{
char[] arr =str.toCharArray();
int firstthree=0;
int lastthree = 0;
for(int i=0;i<3;i++){
if(Character.isDigit(arr[i]))
firstthree = firstthree +Character.getNumericValue(arr[i]);
}
for (int i=arr.length; i>arr.length-3;i--){
if(Character.isDigit(arr[i-1]))
lastthree = lastthree+Character.getNumericValue(arr[i-1]);
}
if(firstthree==lastthree && firstthree!=0){
System.out.println("the first three digit and last three digit are equal");
}
else{
System.out.println("the first three digit and last three digit are not equal");
}
}
}

}

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

{
/* write a java program to solve sum of first three numbers is equal to sum of last three numbers.
String str="123" 1+2+3 and 3+2+1
String str="678786"
String str="1b8" not equal.*/

public static void main (String[] args){
System.out.println("Program starts");
String str = "abcdfdgd";
if(str.length()<3){
System.out.println("String is not 3 length");
}
else{
char[] arr =str.toCharArray();
int firstthree=0;
int lastthree = 0;
for(int i=0;i<3;i++){
if(Character.isDigit(arr[i]))
firstthree = firstthree +Character.getNumericValue(arr[i]);
}
for (int i=arr.length; i>arr.length-3;i--){
if(Character.isDigit(arr[i-1]))
lastthree = lastthree+Character.getNumericValue(arr[i-1]);
}
if(firstthree==lastthree && firstthree!=0){
System.out.println("the first three digit and last three digit are equal");
}
else{
System.out.println("the first three digit and last three digit are not equal");
}
}
}

}

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

import java.util.Scanner;

//Limitations 1. String length >=3
// 2. Only digits accepted

static final int len = 3;

public static void main(String[] args) {
// TODO Auto-generated method stub

Scanner scn = new Scanner(System.in);

System.out.print("Enter string:");
String str = scn.next();

int firstSum=0, lastSum=0;
boolean exception = false;
System.out.println("Length should be greater than "+CompareThreeDigitsAddition.len);
else {

//simple approach by iterating only once
for(int i=0;i<3;i++){

if(Character.isDigit(str.charAt(i))){
firstSum += Character.getNumericValue(str.charAt(i));

}else{ exception = true;}

if(Character.isDigit(str.charAt(str.length()-1-i))){
lastSum += Character.getNumericValue(str.charAt(str.length()-1-i));
}else{ exception = true;}
}
if( !exception && firstSum==lastSum)
System.out.println("Both are equal "+firstSum);
else{
System.out.println("Exception occured or Both are not equal. firstSum:"+firstSum+" lastSum:"+lastSum);
}

}

}

}

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

private static boolean checkIfFirstThreeNumbersAreEqualToSumOfLastThreeNumbers(String param){
boolean flag = false;
if (param.length() < 3)
flag = false;

else {
int fisrtThreeSum = 0;
int lastThreeSum = 0;
int startIndex = 0;
int lastIndex = param.length()-1;
flag = true;
while (startIndex < 3) {
if(Character.isAlphabetic(param.charAt(startIndex)) || Character.isAlphabetic(param.charAt(lastIndex))) {
flag = false;
break;
}
fisrtThreeSum = fisrtThreeSum+Character.getNumericValue(param.charAt(startIndex));
lastThreeSum = lastThreeSum+Character.getNumericValue(param.charAt(lastIndex));
startIndex++; lastIndex--;
}

System.out.println("FirstThreeSum = "+fisrtThreeSum);
System.out.println("LastThreeSum = "+lastThreeSum);

}
System.out.println("Flag is "+flag);
return flag;
}

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.

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

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