Front-End Engineer in San Francisco – solved code interview questions

I’ve came to this site (via hacker news) had few frontend engineer’s job interview questions. I’ve try to solved it quickly. May be you could solve it even more efficient way. Here are my solutions.

Write a function that takes two sorted lists of numbers and merges them into a single sorted list

    var list1 = [2, 4, 5, 6];
    var list2 = [3, 5, 8, 9];
    merged_list = merge_sorted_list(list1, list2)
    alert(merged_list);

    function merge_sorted_list(list1, list2) {
        merged_list = list1.concat(list2);
        return merged_list.sort(numsort);
    }

    function numsort(a, b) {
        return a - b;
    }

 Given an array of integers (positive or negative) find the sub-array with the largest sum.

 var list = [
      2, -4,
      6, -9, [8, 9, -6],
      12, [45, 3, 7], -34, [7, -2]
  ];

  sublists = [];
  sublists_sum = [];
  for (var i in list) {
      if (Object.prototype.toString.call(list[i]) == "[object Array]") {
          sublistssum = list[i].reduce(function (a, b) {
              return a + b;
          });
          sublists[sublistssum] = list[i];
          sublists_sum.push(sublistssum);
      }
  }
  var max_item = Math.max.apply(null, sublists_sum);
  alert("sub-array with the largest sum is " + sublists[max_item]);

 Determine if a given string is a palindrome

 var input_str = "madam";
 checkIfPalindeom(input_str);

 function checkIfPalindeom(str) {
     if (str == str.split('').reverse().join('')) {
         alert("Yes string " + str + " is palindeom");
     } else {
         alert("No string " + str + " is not palindeom");
     }
 }

Given a large hash table whose keys are movie names and whose values are a list of actors in those movies, write a function to determine the Bacon number of a particular actor.

I'll post solution soon

 

Total
0
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

 
Previous Post

Simple HTML5 geolocation plugin using jQuery

Next Post

JavaScript Quiz – write a one line program to calculate the sum of its digits

Related Posts