- Time Limit: 60 mins
- Internet access is NOT allowed
- Please put your answer in this markdown document
Please answer Part A, and for Part B you can choose 1 or 2 section between Web / iOS / Android
Please indicate which section you have answered (Tips: [x] will mark the checkbox)
- Web
- iOS
- Android
Can you show us how will you design a "MinimalStack", where it provide push and pop but also a getMin() function.
The getMin() returns the minimal integer inside the stack. Ideally in O(1).
Tips:
- Syntax is not important;
- In C++ STL, stack::top return the last element pushed into the stack.
- In C++, you can use stack::pop(); or stack::push(x); to call the parent class method
#include <stack>
using namespace std;
class MinimalStack: public stack<int> {
public:
int pop();
void push(int &x);
int getMin();
};
int MinimalStack::pop() {
}
void MinimalStack::push(int &x) {
}
int MinimalStack::getMin() {
}
Say we have a V-shape Array, which always have a maximal value in it, and the value in the array goes from low to high value and low again... For example: [2,3,5,8,9,3,2], or [1,6,7,8,11,15,11,1]
What's the best way to search the maximal value in the array? Illustrate with pseudocode
What's the different between process and thread? What is the advantage if a server use process model vs thread model?
Let's say you're given a machine, with a C compiler. And you don't know weather the stack pointer of CPU is increment or decrement.
Can you show us how to develop a C program to find that out?
Assume we are designing a image social network, which have the following features:
- We have users
- Users can upload multiple images
- Each images can have multiple tags
- Users can follows each others
- Users can follows tags
- There will be a newsfeed showing all of the latest images with tags or uploaded by users followed by the logged in users
Can you describe how will you setup a database for the above software?
(Brief table schema for SQL or document structure for non-SQL database)
For the database you designed in Answer 5.1, how will you get the images for the news feed of a user? (Assume the user ID is 5 or username is johndoe)
How would you optimize a website assets / resources loading speed? List at least 3 approach.
Why is it better to serve site assets from multiple domains? Is there any exception?
Can you explain the difference between GET and POST method?
The expected output of the following javascript code is alert count down from 5 to 0. Explain why it doesn't work and fix the bug:
function count (num) {
for (var i = 0; i <= num; i += 1) {
setTimeout(function () {
alert(num - i);
}, i * 1000);
}
}
count(5);
CSRF is a very common kind of attack which makes authenticated users do something they don't expect. For example:
Alice wishes to transfer $100 to Bob using the bank.com web application that is vulnerable to CSRF. Maria, an attacker, wants to trick Alice to send the money to her instead. The attack will comprise the following steps:
- building an exploit URL
- tricking Alice to click on the URL
The URL Alice click to transfer $100 to Bob on bank.com is as follows:
GET https://bank.com/transfer.do?acct=BOB&amount=100
Maria constructs the following exploit URL which will transfer $100,000 from Alice's account to her account, and make it looks like an iPad lucky draw.
<a href="https://bank.com/transfer.do?acct=MARIA&amount=100000">Click and win an iPad!</a>
As a developer, how will you fix the security problem of bank.com? Illustrate with relevant pseudo-backend code OR HTML.
What's the different between NSMutableArray and NSArray? When to use which?
What's the different between UIView frames and bounds
Can you give 2 / 3 ways to detect when a view is touched on iOS?
What's method swizzling and give an example of when would you use it?
Given three objects, A,B and C.
- A retains B
- B retains C
- C retains B
Now A releases B, explain what happens and propose ways to avoid the problem.
What will happen with a method invoke to nil
Do you know / Can you guess for operations below, which is faster amongst NSArray vs NSSet? Why?
- Create new items incrementally:
- Iterating items:
When a user using your app, describe 3 ways onPause() will be called by user's action.
Under what situation will the following code crash your app?
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, textMessage);
sendIntent.setType(HTTP.PLAIN_TEXT_TYPE); // "text/plain" MIME type
startActivity(sendIntent);
Do you know / Can you guess for operations below, which is faster amongst HashSet vs ArrayList? Why?
- Create new items incrementally:
- Iterating items:
What are the different between String, StringBuilder and StringBuffer? When to use which?
Suggest a scenario you want to use Service instead of AsyncTask, why?
You have an AsyncTask do a query and callback to update UI. When will you trigger execution in a fragment lifecycle? onAttach or onStart. why?
WeakReference vs LruCache, which one is better? Breify explain how LruCache works.