Tuesday, February 13, 2018

java questions


  • Given a binary tree, how to get the sum of vertical lines.
tip: try to find a solution with  linear time computation. Use a HashMap to store the sums.
  • Given a multi-million nodes linked List, how to get the value of the Nth node counting from the tail.  
tip: use 2 pointers and save an iteration
  • Implement a HashMap with TTL.
tip: override HashMap
  • Given a n X n matrix: find the count of the number chains, for example, the following matrix have 2 number chains. Also find the length of the longest chain, for example, the following matrix have max length 7.
1 2 3 0 0 0
0 0 4 5 0 0
0 0 0 6 0 0
0 1 0 7 0 0
0 2 0 0 0 0
0 3 4 0 0 0

tip: Map union and DFS
  • Given a nXn matrix, find the count of connected areas, for example the following matrix have 2 connected areas.

1 2 3 0 0 0
0 2 4 5 0 0
0 5 0 6 0 0
0 0 0 7 0 0
0 2 0 0 0 0
9 3 4 0 0 0

tip: Map union
  • write a java class that handles bank account deposit, withdraw and sum.
tip: consider 3 tier web application, this code could run in multiple app VMs.
  • write a function that returns if two words have the same characters. For example: func("file", "lief") should return true.
tip: HashMap
  •  A file looks like the following, the first column is the name, the second column is the versions. Read the file in and order the records by the versions.
aafdfad   12.34.1
dfadfadfadf     13.7.90
adfadfadfad   1.2.5.8
dfadfadf         9.0.33

tip: consider library quality code, edge conditions and unit tests.
  • A new IOT thermometer is invented and selling to general public, it is low power, low memory device. Design a system that updates its firmware.
tip: consider board type, micro OS, httpClient, geographically distributed update, selective update, failed update recover, cloud storage, log report, error report, batched roll out, pilot deploy, black out handle, oob handle, traffic zip etc.
  • Design a web application that takes start date, end date and city, returns the prices for hotels.
tip: consider thread pool, rest services, factory design pattern, future with timeout, third party content cache, scheduledThreadPool, periodic update, load balancer, database row lock, input/output validation etc.
  • Try to give an implementation of cloud storage system.
tip: hypervisor, unix file system or NoSQL, blob, item Id, global read-only but regional write, data center ETL, eventually consistent, object serialization and deserialization.
  • Design a program to output the percentage of english, Thai, French etc. words in an article.
tip: character frequency statistics
  • A program read millions of time ordered records through a third party api. Due to number round issue, the last few records returned from the third party api are not stable. How to work around this inacuracy in the program. 
tip: understand how the round issue happen and took more records so that the round issue caused inaccruacy will fall within the range. 
  • Design a program that downloads and parses logs to generate events.
tip: through what api the logs are downloaded, why choose rest/soap/http/raw socket, AAA, how to parse, generate event, blocking queue, database update, integrate, program monitoring, log, deployment, what actions will be triggered by certain events, how event flow at back end, inter process communication, etc.

Phone interview with SecureWork

A draft dated back at 2009

Just have a phone interview with the SecureWork for a senior java developer position.
The interview style is straight to the point.
Securework: hi, how are your doing tody?
Me: I'm doing well, thank you.
Securework: So the projects we will actually do is ... Now, I will ask you some questions about java to see if you are a good fit.
SecureWork: What's a abstract class?
Me: blablabla.
SecureWork: Ok. In what situation we prefer interface instead of abstract class?
Me: blablabla.
SecureWork: Ok. What is static Class?
Me: blablabla.

The interview going like this for half an hour, all aspects of java are asked. I guess he must have a standard question lists at hand and was keep scoring. The following is the questions I remember.

What is volatile variables?
What is keyword final?
What is keyword finally?
What is keyword static?
Explain auto-boxing.
Can I call a constructor through another constructor?
Can I call method of the super class?
What's the difference between sleep and wait?
In a multi-threading environment, how can you prevent methods to interfering each other?
Can you explain garbage collector?
When an object get garbage collected?
Will an object get garbage collected once it go out of scope?
Will garbage collection prevent memory outrage?
Can you give me an example of memory leakage in java programming?
What's the difference between the handeled and un-handeled Exceptions?
What's the differece between List and Set?
When we use LinkedList instead of Array?
When we use Array instead of LinkedList?
Please explain serilization?
What function you call to make serialization happen?
What's the difference between String and StringBuffer?
What's the difference between InputStream, OutputStream and PrintWriter, PrintReader?
Explain the keyword transient.
What's the difference between stack and queue?
When we use HashMap, and we we use TreeMap?
What is the Generic?
Give an example when you should use generic.
...
SecureWorks: So, I will ask some questions on linux. I have two very large files on two machines. The link between the two machines is very slow. Now I want to compare the two files in a short time, how will you do it?
Me: blablabla.

SecureWorks: Have you worked on database before?
Me: yes, blablabla.

SecureWorks: I will gonna ask you a few questions.
What is an index?
What's the difference between inner join and outer join?

SecureWorks: Now a design question. I have a webserver with heavy traffic. The user submits a word and the system looks up the dictionary and returns the explanation. We want achieve the best performance without too much cost. How will you go for it?

Then it is the interactive disscussion.

Finally, he stopped asking questions and began to introduce the projects they are doing recently and the agile developing strategy they are using for the projects.
He then asked my salary expectation and avialability for onsite interview next week.

I asked him what kind of questions I should prepare. He suggest me to put emphasis on algorithms.

The phone interviw lasts for about 1 hour.

chatgpt's view about universe

 is there god? The existence of a higher power, commonly referred to as "God," is a matter of personal belief and faith. There is ...