## xyz Interview Question for Backend Developers

• 0
of 0 votes

Country: United States
Interview Type: Phone Interview

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

Complexity O(2*n/2) = O(n)

``````public String[] reverseArrayWithModification(String[] arr) {
String[] out = new String[arr.length - 1];
int middle = arr.length / 2;

if (arr[middle].equals("&")) {
for (int i = 0; i < middle; i ++) {
out[i] = arr[arr.length - 1 - i];
}
for (int i = middle + 1; i <= 2 * middle; i ++) {
out[i - 1] = arr[i - middle - 1];
}
} else {
throw new IllegalArgumentException("Input array has no char '&'");
}
return out;
}``````

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

Thanks Denis. Do you have java solution as well ?

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

Elegant Python Solution :)

``````def reverseAfterMiddle(nums):
mid = len(nums) // 2
return nums[mid+1:][::-1] + nums[0:mid]

print(reverseAfterMiddle([1,2,3,4,'&',12,13,14,15])) # prints [15, 14, 13, 12, 1, 2, 3, 4]
print(reverseAfterMiddle([33,34,'&',55,63])) # prints [64, 55, 33, 34]``````

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

String []st=input.split(",");
List<String> list=new ArrayList<>();
boolean isDetected=false;
int l=0;
int r=st.length-1;
while(l<=r){
String temp=st[r];
if(temp.equalsIgnoreCase("&")){
isDetected=true;
r--;
continue;
}
if(isDetected){
temp=st[l];
list.add(temp);
l++;
}else{
list.add(temp);
r--;
}
}
System.out.println(list);

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

``````String []st=input.split(",");
List<String> list=new ArrayList<>();
boolean isDetected=false;
int l=0;
int r=st.length-1;
while(l<=r){
String temp=st[r];
if(temp.equalsIgnoreCase("&")){
isDetected=true;
r--;
continue;
}
if(isDetected){
temp=st[l];
list.add(temp);
l++;
}else{
list.add(temp);
r--;
}
}
System.out.println(list);``````

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

``````{{
String []st=input.split(",");
List<String> list=new ArrayList<>();
boolean isDetected=false;
int l=0;
int r=st.length-1;
while(l<=r){
String temp=st[r];
if(temp.equalsIgnoreCase("&")){
isDetected=true;
r--;
continue;
}
if(isDetected){
temp=st[l];
list.add(temp);
l++;
}else{
list.add(temp);
r--;
}
}
System.out.println(list);``````

}}

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

String []st=input.split(",");
List<String> list=new ArrayList<>();
boolean isDetected=false;
int l=0;
int r=st.length-1;
While(l<=r){
String temp=st[r];
if(temp.equalsIgnoreCase("&")){
isDetected=true;
r--;
continue;
}
if(isDetected){
temp=st[l];
list.add(temp);
l++;
}else{
list.add(temp);
r--;
}
}
System.out.println(list);

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