Trulia Phone Interview


1) Difference between interface and abstract class. Write code to show example of each. Can a class derive from abstract class and implement an interface as well? (Yes)

2) Write a function to test a palindrome.

Javascript :
1) What is the difference between
x = 1;
var x = 1;
window.x = 1;

2) Write a function to add an array of numbers using the arguments variable

var data = [1,2,3,4];

function sum() {
   var myData = arguments[0];
   return myData.reduce(function (acc, num) { acc += num; return acc});

3) write a function to implement mult(4)(5)

function mult(x) {
   return function(y) {
       return x*y;

var ans = mult(4)(5);

4) Write a function to output alert(1), alert(2) every 1 second till 5 times
Similar to question asked in Ten-X interview.

5) write a function to put spaces in a string “Hello World” ==> “H e l l o W o r l d”.

var spacify = function (str) {
    return str.split('').join(' ');


Is it possible to write a function spacify like “hello world”.spacify()

String.prototype.spacify = String.prototype.spacify || function() {
  return this.split('').join(' ');


Yahoo Phone Interview

1) Write a function to accept seconds and print time in format hh:mm:ss
2) If the same function is to be used multiple times how would we optimize the code so that we don’t have to calculate it each time. (hint: use static)

function formatTime($seconds) {
    if !($seconds) {
        return "";
    static $timeArray = array();
    if (isset($timeArray[$seconds])) {
        echo "using cache\n";
        return $timeArray[$seconds];
    $origSeconds = $seconds;
    $hours = floor($seconds / 3600);
    $seconds = $seconds % 3600;
    $mins = floor($seconds / 60);
    $seconds = $seconds % 60;
    $ret = sprintf("%02d::%02d::%02d", $hours, $mins, $seconds);
    $timeArray[$origSeconds] = $ret;
    return ($ret);

3) Can cookies be stolen ?
Yes cookies can be stolen. XSS is one way to do it.

4) Interface vs Abstract class
5) When does the page on screen get refreshed ?
Repainting and Reflowing

Qualys Phone Interview

1) Difference between interface and abstract class
2) How would you provide security to a web application?
3) Diff between call by value and call by reference
4) Multiple inheritance in PHP
5) Does PHP pass objects by reference or by value
6) What is ob_start in PHP
7) Which Design Patterns have you worked with?
8) Difference between valid xml and well formed xml

8) Given a string “This is Bob who has been working since 2002 in this industry. Wow 2002.”
write a program to determine which words in this string are palindromes.
Output should be

Things to remember while writing the solution:
1) lowercase the string while checking for palindrome
2) Remove fullstops,etc. Account for multiple spaces between words.
3) The string can contain multiple Bob or 2002. So use a hash table to store the palindromes which are found. So that if that word occurs again then you don’t have to process it again.

9) Given the following schema, write a query which will produce the given output:

   1    A
   2    B
   3    C

   1    John 
   2    Matt
   3    Allie

  1              1
  2              2
  3              1

   A       John, Allie
   B       Matt
   C       NULL

    FROM grade G 
        LEFT JOIN student_grade SG 
              ON G.ID = SG.grade_id
        LEFT JOIN student S
              ON S.ID = SG.student_id

Ten-X Interview

1) Write a javascript function to print an array slowly (e.g each element in intervals of 500 ms). Example of array : 1,5,6,’cool’,8. Once done then print “all done”.


function foo(i) {
   var arr = [1,5,6,"cool",8];
   console.log("i:" + i + ":" + arr[i]);


function foo2() {
   console.log("all done");

for (i=1; i <=3 ; i++) {
    setTimeout(foo, i*500, i);

setTimeout(foo2, (i)*500);

Disadvantage in Method-1 is that so many setTimeout will be in memory. In Method-2 the number of setTimeout in memory will be less.


var arr = [1,5,6,"cool",8];
var i = 0;

function foo() {
   console.log("i:" + i + ":" + arr[i]);
   if (i > arr.length) {
       console.log("all done");
   } else {
       setTimeout(foo, 500);

setTimeout(foo, 500);


const arr = [10, 12, 15, 21];
for (let i = 0; i < arr.length; i++) {
  // using the ES6 let syntax, it creates a new binding
  // every single time the function is called
  // read more here:
  setTimeout(function() {
    console.log('The index of this number is: ' + i);
  }, 3000);


for (i = 0, max = 9; i < max ; i ++) {
  setTimeout(printFunc(i), 500*i);

function printFunc(i) {
   return function() {

2) Given a string "San Francisco Hotel" and a array of strings (e.g. San Jose Culture of Art, Father Francisco and San Mateo", "I love schools") etc find out the best match. For example in above "Father Francisco and San Mateo is best match since it contains San and Francisco.

3) Given a sorted array return a random array.

4) Given an array of N numbers return the max product of 3 numbers. Example if the array contains [4,2,7,5,3] then the max product possible is 4 * 7 * 5 = 140.

5) In Javascript Using functional programming , given an array of numbers, return the sum of their squares.

var arr = [2,4,6,8];

var sum = { return s*s;}).reduce(function(acc, val) {return acc + val;});

Interview questions from Pinank

here are the questions:
1. Given a library of Stack with 2 functions (push(x), pop()), implement a queue library (i.e. enqueue(x), dequeue())
Use 2 stacks:
enqueue() : keep push(x)ing in Stack1 only
dequeue() : keep pop()ing from Stack2 only. (Incase Stack2 is empty, pop() everything from Stack1 to push() into Stack2) and then pop() from Stack2

2. Explain working of HTTP protocol (some people answer in quite detail (about DNS lookup, TCP handshake, etc.)

3. How can you implement a HashTable?
Use an ‘Array’ to store values. (Each array element is actually a linked-list, so 2 values having same key can be inserted at the same-element in the Array.
Also need 2 functions:
a) to get hash-key (to decide where to store the element in the array)
b) compare() : I forgot the exact reason, but i think its used for resolving collision. (In Java they also store the ‘key’ along with the object’ instead of just storing the object and this compare() function is then used .. i’ll try to find the document that has more details on how its used..
c) Some people also ask what are good options of hash-functions ? (it will depend on type of data, but some common options are ‘mod’ function) e.g. 57 mod 8 = 1 (if array size is 8) ..

Must Know Algorithms

As per Cracking the Coding Interview:

Data Structures
Linked Lists
Binary Trees
Hash Tables

Breadth First Search
Depth First Search
Binary Search
Merge Sort
Quick Sort
Tree Insert/Find/etc

Bit Manipulation
Singleton Design Pattern
Factory Design Pattern
Memory (Stack vs Heap)
Big-O Time

Software Architect Interview Questions

What do you understand from the word Architecture? What is meant by software Architecture?

What kind of Software Architecture have you designed till now? Can you explain with the help of commands and patterns?

Which kind of design patterns have you used while building software architecture?

Explain pattern? What is design pattern and factory pattern? Where can these be used?

What is the use of builder pattern? Why it is so important in Software Architecture?

What is shallow copy and deep copy in prototype pattern? Describe: singleton and command pattern?

Numerate the advantages and disadvantages of composition and inheritance in Software Architecture?

When do you use abstract class and what are the conditions to use interfaces?

Explain the difference between object oriented, interface oriented and aspect oriented design and programming?

In which case do you use interface oriented and aspect oriented designs?

Difference between Object Oriented Programming and Component Oriented Programming