Skip to content

Instantly share code, notes, and snippets.

@chpapa
Created August 8, 2015 04:20
Show Gist options
  • Save chpapa/2ed5cea74b9d34b19ddd to your computer and use it in GitHub Desktop.
Save chpapa/2ed5cea74b9d34b19ddd to your computer and use it in GitHub Desktop.

Instructions

  • 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

Part A

Question 1

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

Answer 1

#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() {
}

Question 2

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

Answer 2

Question 3

What's the different between process and thread? What is the advantage if a server use process model vs thread model?

Answer 3

Question 4

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?

Answer 4

Question 5.1

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)

Answer 5.1

Question 5.2

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)

Answer 5.2

Web

Question 6

How would you optimize a website assets / resources loading speed? List at least 3 approach.

Answer 6

Question 7

Why is it better to serve site assets from multiple domains? Is there any exception?

Answer 7

Question 8

Can you explain the difference between GET and POST method?

Answer 8

Question 9

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);

Answer 9

Question 10

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.

Answer 10

iOS

Question 11

What's the different between NSMutableArray and NSArray? When to use which?

Answer 11

Question 12

What's the different between UIView frames and bounds

Answer 12

Question 13

Can you give 2 / 3 ways to detect when a view is touched on iOS?

Answer 13

Question 14

What's method swizzling and give an example of when would you use it?

Answer 14

Question 15

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.

Answer 15

Question 16

What will happen with a method invoke to nil

Answer 16

Question 17

Do you know / Can you guess for operations below, which is faster amongst NSArray vs NSSet? Why?

Answer 17

  • Create new items incrementally:
  • Iterating items:

Android

Question 18

When a user using your app, describe 3 ways onPause() will be called by user's action.

Answer 18

Question 19

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);

Answer 19

Question 20

Do you know / Can you guess for operations below, which is faster amongst HashSet vs ArrayList? Why?

Answer 20

  • Create new items incrementally:
  • Iterating items:

Question 21

What are the different between String, StringBuilder and StringBuffer? When to use which?

Answer 21

Question 22

Suggest a scenario you want to use Service instead of AsyncTask, why?

Answer 22

Question 23

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?

Answer 23

Question 24

WeakReference vs LruCache, which one is better? Breify explain how LruCache works.

Answer 24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment