Senior back end engineer Interview Questions

103

Senior Back End Engineer interview questions shared by candidates

Top Interview Questions

Sort: Relevance|Popular|Date
Veeva Systems
Senior Software Engineer, Java Back End was asked...18 August 2015

public class Person { Person father; Person mother; Gender gender; Integer age; List<Person> children; int level = 0; public enum Gender { Male, Female; } } For the above class, you basically have to implement 2 methods. public List<Person> getOldestSisters() public List<Person> getGreatestAncestors()

5 Answers

/** * Returns the Persons which are the greatest number of levels up the family tree * from this instance. Examples: * Given a tree where this person instance only has a mother and father, return mother and father. * Given a tree where this person instance has a mother &amp; father, and a grandfather on the mother's side, return only the grandfather on the mother's side. * @return List of Person */ public List getGreatestAncestors() { // If this is the root of the tree, return empty array because there is no ancestor for the tree if (this.father == null &amp;&amp; this.mother == null) { return new ArrayList(); } List fList = new ArrayList(); List mList = new ArrayList(); if (this.father != null) { fList = this.father.getGreatestAncestors(); } if (this.mother != null) { mList = this.mother.getGreatestAncestors(); } List results = new ArrayList(); for (Person p : fList) { if (results.contains(p)){ continue; } results.add(p); } for (Person p : mList) { if (results.contains(p)){ continue; } results.add(p); } return results; } Less

I cranked this out in about 30 minutes. I believe it works quite well. I've also included the corresponding unit tests: file: Person.java ------------------------------------------------------------------------------------------------------------- package Command; import java.util.ArrayList; import java.util.HashSet; import java.util.List; public class Person { Person father; Person mother; Gender gender; Integer age; List children; int level = 0; public enum Gender { Male, Female; } Person(Person dad, Person mom, Gender gender, int age, int level) { this.father = dad; this.mother = mom; this.gender = gender; this.age = age; this.level = level; } public void setChildren(List children) { this.children = children; } public void addChild(Person child) { this.children.add(child); } public List getOldestSisters () { // given the current person (self), determine parents // then get children of those parents // Determine gender of each child // Where they are female, get ages // return females with age &gt; mine // Note: must check on both sides father/mother as there may be a mixed marriage // Combine list of children - Exclude YOU as you cannot be your own sister. // Use a set to eliminate duplicates. HashSet allChildren = new HashSet(); // Can't add null to a hashSet so screen for it. if ((father != null) &amp;&amp; (father.children != null)){ allChildren.addAll(father.children); } if ((mother != null) &amp;&amp; (mother.children != null)) { allChildren.addAll(mother.children); } // If you are not in this list, there is an issue! if (allChildren.contains(this)) { allChildren.remove(this); // System.out.println("Removing self from list."); } else { System.out.println("Error: You are not a child of your parents! Adopted?"); } // Filter down to only women and get any older than me: int myAge = this.age; List oldestSisters = new ArrayList(); for (Person child : allChildren) { if (child.gender == Gender.Female) { if (child.age &gt; myAge) { oldestSisters.add(child); } } } return oldestSisters; } public List getGreatestAncestors() { if ((this.father == null) || (this.mother == null)) { return null; // You must have two parents to have ancestors } // Find root parents List myParents = getParents(this); return getElders(myParents); } private List getElders(List parents) { List elders = new ArrayList(); List myParents = new ArrayList(); boolean newElders = false; for (Person parent : parents) { myParents = getParents(parent); if (myParents.isEmpty()) { elders.add(parent); } else { elders.addAll(myParents); newElders = true; } } if (newElders == true) { return getElders(elders); } return elders; } private List getParents(Person person) { List parents = new ArrayList(); if (person.father != null) parents.add(person.father); if (person.mother != null) parents.add(person.mother); return parents; } } // For the above class, you basically have to implement 2 methods. // public List getOldestSisters() // public List getGreatestAncestors() Less

package Command; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; import static org.junit.jupiter.api.Assertions.*; class PersonTest { // Create grand parents Person grandFatherDad = new Person(null, null, Person.Gender.Male, 78, 1); Person grandMotherDad = new Person(null, null, Person.Gender.Female, 81, 1); Person grandFatherMom = new Person(null, null, Person.Gender.Male, 69,1); Person grandMotherMom = new Person(null, null, Person.Gender.Female, 89, 1); // Create parents / aunts and uncles Person father = new Person(grandFatherDad, grandMotherDad, Person.Gender.Male, 48, 2); Person mother = new Person(grandFatherMom, grandMotherMom, Person.Gender.Female, 47, 2); Person aunt1 = new Person(grandFatherMom, grandMotherMom, Person.Gender.Female, 47, 2); // Twin sis to mom Person aunt2 = new Person(grandFatherDad, grandMotherDad, Person.Gender.Female, 37, 2); Person uncle1= new Person(grandFatherDad, grandMotherDad, Person.Gender.Male, 35, 2); // Children (me and bros and sis) Person self = new Person(father, mother, Person.Gender.Male, 18, 3); Person brother1 = new Person(father, mother, Person.Gender.Male, 16, 3); Person sister1 = new Person(father, mother, Person.Gender.Female, 15, 3); Person sister2 = new Person(father, mother, Person.Gender.Female, 14, 3); @BeforeEach void setUp() { // Create children / sibling groups List children = new ArrayList(); children.add(father); children.add(aunt1); children.add(uncle1); grandFatherDad.setChildren(children); grandMotherDad.setChildren(children); children.clear(); children.add(mother); children.add(aunt2); grandFatherMom.setChildren(children); grandMotherMom.setChildren(children); children.clear(); children.add(self); children.add(brother1); // Dad had brother with other wife children.add(sister2); father.setChildren(children); // mom came with her own daughter from prior marriage children.clear(); children.add(self); children.add(sister1); children.add(sister2); mother.setChildren(children); } @AfterEach void tearDown() { } @Test void getOldestSisters() { // When there are no older sisters and I am male: //Person me = new Person(father, mother, Person.Gender.Male, 48); List olderSisters = null; olderSisters = self.getOldestSisters(); assertTrue(olderSisters.isEmpty(), "No older sisters."); // When there is one older sister and I am male Person sister3 = new Person(father, mother, Person.Gender.Female, 50, 3); mother.addChild(sister3); father.addChild(sister3); olderSisters = self.getOldestSisters(); assertTrue(olderSisters.contains(sister3)); assertTrue(olderSisters.size() == 1, "One older full sister."); // Youngest Sister has two older sisters (one full, one half) olderSisters.clear(); olderSisters = sister2.getOldestSisters(); assertTrue(olderSisters.contains(sister1)); assertTrue(olderSisters.contains(sister3)); assertTrue(olderSisters.size() == 2, "One older full, one older half"); } @Test void getGreatestAncestors() { List ancestors = self.getGreatestAncestors(); assertTrue(ancestors.size() == 4); assert(ancestors.contains(grandFatherDad)); assert(ancestors.contains(grandFatherMom)); assert(ancestors.contains(grandMotherDad)); assert(ancestors.contains(grandMotherMom)); ancestors = father.getGreatestAncestors(); assertTrue(ancestors.size() == 2); assert(ancestors.contains(grandFatherDad)); assert(ancestors.contains(grandMotherDad)); ancestors = mother.getGreatestAncestors(); assertTrue(ancestors.size() == 2); assert(ancestors.contains(grandFatherMom)); assert(ancestors.contains(grandMotherMom)); ancestors = grandFatherDad.getGreatestAncestors(); assertNull(ancestors, "getGreatestAncestors():Persons with no ancestors should return null."); } } Less

Show More Responses
RetailMeNot

SQL: you have a table with customers, with gender m and f. Write a query to update m with f, f with m in a single query, without temporary tables

2 Answers

UPDATE customers SET gender = CASE WHEN gender = 'm' THEN 'f' WHEN gender = 'f' THEN 'm' END Less

UPDATE customers SET gender = CASE WHEN gender = 'm' THEN 'f' WHEN gender = 'f' THEN 'm' END Less

Mastery Logistics Systems

How would you design a data ingestion framework?

1 Answers

Huh... Im applying. Hope I dont get these Questions, and Wash Cycle of Interviews / Shuffling of Contacts / Waiting game... It tends to Taint my vibes. This isnt the City, Its Champaign Urbana. I enjoy the subtle On-boarding..... shinsetsu.xyz Less

RetailMeNot

$a = "VeryLongString"; return char that appears only once.

1 Answers

I have used array_count_values() but they didn't know about this PHP function, so my solution was not taken into account. The proposed solution was to parse the string as an array and keep the number of occurrences in a separate array. Less

GE Power

Make a function to detect a palindrome word using only one string variable (the one passed as a parameter).

1 Answers

Using a for loop to compare each character of the word in a mirror-way, the first character against the last, the second against the second to last, and so on. Whenever a difference was found, the function returned false, otherwise, true was returned indicating the word was a palindrome. Less

Jimdo

you get an automatic reply containing as assignment , that will take you couple of days to complete. then they reply something like....your CV does not match our desired skill set, that't it!!! (are you serious?!)

1 Answers

applying for this company is just wasting the time, they do not care about people's time Less

RetailMeNot

[1,6,5,4,2] -> write an algorithm to return second larger number in the array, in this case number 5

1 Answers

asort($a) return $a[1]

Bank of America

There were like 7 different shapes, like circles and squares.

1 Answers

I placed them in order of their shapes and it really impressed the HR rep. She said that most people put them in order of size?? :) Less

Atlassian

System design for a simple API request, saving data to database, pros and cons of different design decisions.

1 Answers

Explain your thought process out loud and take initiative on solutioning.

Peek

complete a 10 hour take home coding challenge

1 Answers

no

Viewing 1 - 10 of 103 Interview Questions

See Interview Questions for Similar Jobs

software engineer