wealthfront电面面经 整理自Glassdoor

来源:互联网 发布:stringbuffer拼接json 编辑:程序博客网 时间:2024/06/06 09:00

1. what is immutable?

Immutable means that once the constructor for an object hascompleted execution that instance can't be altered.

This isuseful as it means you can pass references to the object around, withoutworrying that someone else is going to change its contents. Especiallywhen dealing with concurrency, there are no locking issues with objects thatnever change

Some famous immutableclasses in the Standard API:

·      java.lang.String (already mentioned)

·      The wrapper classes for the primitive types: java.lang.Integer,java.lang.Byte, java.lang.Character, java.lang.Short, java.lang.Boolean,java.lang.Long, java.lang.Double, java.lang.Float

·      java.lang.StackTraceElement (used in building exceptionstacktraces)

·      Most enum classes are immutable, but this in fact depends on theconcrete case. (

·      java.math.BigInteger and java.math.BigDecimal(at least objects of those classes themselves, subclasses could introducemutability, though this is not a good idea)

 

2. two sum,return all pairs

只不过具体的接口要求是每个面试官自己给的,我遇到的这个要求输出的是List<Pair<Long, Long>>>,然后很多针对面向对象的follow up.

3. 问了why wealthfront,找工作的时候最看重公司哪一点等等,还有一些java问题比如TreeMapHashMap的区

Thereare 4 commonly used  implementations of Map in Java SE - HashMap, TreeMap,Hashtable and LinkedHashMap. If we use one sentence to describe eachimplementation, it would be the following:   

  • HashMap is implemented as a hash table, and there is no ordering on keys or values. 
  • TreeMap is implemented based on red-black tree structure, and it is ordered by the key. 
  • LinkedHashMap preserves the insertion order
  •  Hashtable is synchronized, in contrast to HashMap. 

Thisgives us the reason that HashMap should be used if it is thread-safe, sinceHashtable has overhead for synchronization. 


 

4. 实现一个lambda lazy generatoriterator..就是告诉你java可以: list.stream().map((x)->x*x),本质是一个iterator,实现它。。 

5. it’s also helpful to be able to use lambda and streamingfrom java8

6. read their blogknow their products

7. what is your approach to testing code?

8. what happens when you go to a website?

9. return the duplicates from two lists

10. magic index: binary search

Mid = (start+end)/2, 如果mid>Array[mid],查找mid右边,反之查找mid左边

11. spiral matrix ( LC 54)

12. copy list with random pointer (LC 138) hashmap,先把node复制一下,然后对每个node的复制node赋值next random

13. TDD: test driven development

Test-driven development (TDD) is a software developmentprocess that relies on the repetition of a very short development cycle:Requirements are turned into very specific test cases, then the software isimproved to pass the new tests, only. This is opposed to software developmentthat allows software to be added that is not proven to meet requirements.

14. Given a 2-D array of ints where any given valuecan be a 0 or 1, find all locations (corners/coordinates) of rectangles of0's. 

15. java 8 features

16. comparator 用法,用在collection.sort(collectionc, new comparator<>(){})

17. collection

Collection接口中的方法:

增加

add(E e)  添加成功返回true,添加失败返回false.

addAll(Collection c)  把一个集合的元素添加到另外一个集合中去。

 

 

删除

clear()

remove(Object o)

 

removeAll(Collection c)

retainAll(Collection c)

 

查看size()

判断:

isEmpty()

contains(Object o)

containsAll(Collection<?> c)

 

迭代:

toArray()

iterator()

 

18.

 

 

 

 

 

 

 

 

18. What is the difference between a comparable anda comparator.  

Comparable

Comparator

1) Comparable provides single sorting sequence. In other words, we can sort the collection on the basis of single element such as id or name or price etc.

Comparator provides multiple sorting sequence. In other words, we can sort the collection on the basis of multiple elements such as id, name and price etc.

2) Comparable affects the original class i.e. actual class is modified.

Comparator doesn't affect the original class i.e. actual class is not modified.

3)Comparable provides compareTo() method to sort elements.

Comparator provides compare() method to sort elements.

4) Comparable is found in java.lang package.

Comparator is found in java.util package.

5) We can sort the list elements of Comparable type by Collections.sort(List) method.

We can sort the list elements of Comparator type by 

Collections.sort(List,Comparator) method

 

19. Fizz Buzz question (LC 412) discussion 1

20. First round:What should you implement to make a object iterable in foreach? Runtime ofhashmap vs treemap. How to concatenate stream of strings to a string in lineartime?

Second round: Two sum question. Given avariable final int [], can that variable be mutable?
 

21. NDA (involved string manipulation using ArrayList andHashTable).  

22. How to implement a lazy number generator in Java 8? 

 

 

23. what is treemap?

TreeMap isRed-Black tree based NavigableMap implementation. It is sorted according to thenatural ordering of its keys. ... The main difference between them is thatHashMap is an unordered collectionwhile TreeMap issorted in the ascending order of its keys.

24. basic linked list, stacks, sorting, recursion,paths ...  

25. How are options priced  期权是怎么定价的

26. What's the runtime of a good sorting algorithm? 

Arrayquicksortlinkedlistmergesort

27. Implement a function to return the power of a number.Once I got that right, I was shown a class implementation and asked if that wasImmutable.  

跟面经一样http://www.1point3acres.com/bbs/thread-86427-1-1.html

Leetcode 50 pow

 

28. How to access a array with thread safe.  

Operation on array in java is not thread safe. Instead you mayuse ArrayList with Collections.synchronizedList()

Suppose we are tryingto populate a synchronized ArrayList of String. Then you can add item to thelist like -

List<String> list =

         Collections.synchronizedList(newArrayList<String>());

 

       //Addingelements to synchronized ArrayList

       list.add("Item1");

       list.add("Item2");

       list.add("Item3");

Then access them from a synchronized block like this -

synchronized(list) {

       Iterator<String>iterator = list.iterator();

       while(iterator.hasNext())

       System.out.println(iterator.next());

Or you may use a thread safe variant of ArrayList - CopyOnWriteArrayList

https://beginnersbook.com/2013/12/how-to-synchronize-arraylist-in-java-with-example/

29. What are common HTTP verbs and give explanations foreach 

POST, GET,PUT, PATCH, and DELETE.

30. timecomplexity of mergesort

31. treetraversal

32. why can’t you sort a set?

A HashSet does not guarantee anyorder of its elements. If you need this guarantee, consider using a TreeSet tohold your elements.

However if you just need yourelements sorted for this one occurrence, then just temporarily create a Listand sort that:

33. How do you sort a list in Java?  

34. How do you see your career evolving over time? What areyou best at, and how will you do that at this company?  

35. Implement the Set collection in Java(add and removemethods)  

36. Implement connection pooling.  

37. Implement a simple regexp matcher using finiteautomata. 

38. What is the "final" keyword used for? 

https://stackoverflow.com/questions/15655012/how-final-keyword-works

Final keyword has a numerous way to use:

·      A final class cannot besubclassed.

·      A final method cannotbe overridden by subclasses

·      A final variable canonly be initialized once

 

原创粉丝点击