Posts

Showing posts with the label algorithm

Android Job Interview Questions

Image
In this post, I tried to wrote some Job interview questions, that I met during my Job interview journey. Yeah, some of the them are still so fresh, because I mess up them a lot. However, A sketch notebook is always better than a good memory, especially in the situation of the lack practice exercise. finalize function The finalize method is used in JVM’s GC collection. But, it was said that it never guaranteed to be called during the collection, that’s means unpredictable, so I guess why I should put the resource release code into an unpredictable method, still be puzzled. How to write a singleton and thread-safe class? Following is an ordinary Singleton class without thread-safe features. public class Singular { private static Singular sInstance ; private Singular ( ) { } public static Singular getInstance ( ) { if ( sInstance = = null ) { sInstance = new Singular ( ) ; } return sInstance ; ...

A sort algorithm question from a job interview

Image
A sort algorithm question from a job interview Table of Contents Question My Answer After rethinking the question 1 Question Here we are, there is an abstract data type(ADT), which has two members - student number and student score, to represent a student, and there are a millions of the students and the score is ranged from 1 to 100 as integer, there is a container to store this ADT, maybe an array. So please tell me one student's position in this exam in the fastest way. 2 My Answer If you wanna design an algorithm, there are only two points, which you need to focus, space efficiency and time efficiency. They are a perpetual conflict, you can never achieve both space and time efficiency at the same time. Then after a silent break, yeah, I was thinking this question, I believe I gave the stupid answer, just iterate the whole container. Damn it. 3 After rethinking the question The interviewer gave me a hint to finding the most time efficient wa...

Ways to reverse one-directional list

Image
Ways to reverse one directional list Table of Contents 1 How I get this question? 2 So the answer is? 3 What did I learn from this question? 1 How I get this question? I attended a job interview again yesterday, the interviewer asked me some many questions including object-oriented software design, data structure, and algorithms. The written examination which is android SDK related should be my strong points one years ago, but Now I forgot most of the terms. So sucks huh! I list the following topics from my memory after the lasting 3 hours job interview. Plugin design patterns: Cons and Pros, How eclipse project leading this tide. Dynamic Programming language and OOP Lisp language, Functional programming, and Recursion Algorithms Most of the questions enlightening me so much, this interviewer is obviously a good engineer.  wow… Great job. Now, come back the topic. How to reverse a one-directional list? This question was given when we discuss the fu...

An Algorithm for rotating a sequence

Image
An algorithm for rotating a sequence I attended a job interview today, the interviewer asks me a question about how to rotate a sequence with a good space efficiency. I believe I give him a terrible answer. And the interviewer gives me his answer, well, thanks him a lot. So how to rotate a sequence? There is a sequence blow?  +--+--+--+--+--+--+--+--+ | 1| 2| 3| 4| 5| 6| 7| 8| +--+--+--+--+--+--+--+--+ then rotate the sequence to left by 3? what we get is as following. +--+--+--+--+--+--+--+--+ | 4| 5| 6| 7| 8| 1| 2| 3| +--+--+--+--+--+--+--+--+ So  the following step to step tutorial is  a space efficiency way. reverse the first 3 sequence. reverse the last (8 - 3) = 5 sequence. reverse the whole sequence. Then, we get the result sequence which rotates to left by 3 items. I don't know whether it is the best way. I mean both the best space efficiency and time efficiency.  orignal sequence n =3 +--+--+--+--+--+--+--+--+...