Monthly Archives: March 2017

PHP call_user_func vs just calling function

Always use the actual function name when you know it. call_user_func is for calling functions whose name you don’t know ahead of time but it is much less efficient since the program has to lookup the function at runtime. Also … Continue reading

Posted in PHP | Leave a comment

PHP ArrayAccess and ArrayObject

In very simple terms, ArrayAccess is an interface, which you can implement in your own objects; ArrayObject, on the other hand, is a class, which you can either use or extend. ArrayAccess is an interface built in to PHP which … Continue reading

Posted in PHP | Leave a comment

PHP Generators

Generators are functions that provide a simple way to loop through data without the need to build an array in memory. “yield” is the main command here. function getRange ($max = 10) { for ($i = 1; $i < $max; … Continue reading

Posted in PHP | Leave a comment

SQL Brushup

http://a4academics.com/interview-questions/53-database-and-sql/397-top-100-database-sql-interview-questions-and-answers-examples-queries?showall=&limitstart= Get employee details from employee table whose employee name are “John” and “Roy” Select * from EMPLOYEE where FIRST_NAME in (‘John’,’Roy’) Get employee details from employee table whose employee name are not “John” and “Roy” Select * from EMPLOYEE … Continue reading

Posted in Database | Leave a comment

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. … Continue reading

Posted in Interview Questions | Leave a comment

Function overloading in Javascript

Unique things about arguments in functions in Javascript: 1) You can pass any number of parameters to a function without causing an error. 2) You can also pass in no arguments but still make use of arguments inside the function … Continue reading

Posted in Javascript | Leave a comment

Identifying Primitive and Reference Types in Javascript

5 Primitive Types: Number, Boolean, String, Null, Undefined typeof “abc” => string typeof “true” => boolean typeof will work for mostly all of above except null. typeof null will return “object”. So to verify “null” just compare to null. (value … Continue reading

Posted in Javascript | Leave a comment

Find kth largest element in an unsorted array

Method 1 (Simple Solution) A Simple Solution is to sort the given array using a O(nlogn) sorting algorithm like Merge Sort, Heap Sort, etc and return the element at index k-1 in the sorted array. Time Complexity of this solution … Continue reading

Posted in Algorithms | Leave a comment

Longest Substring between 2 Strings

Algorithm: 1) Make a matrix m x n where m = string1 length and n = string2 length 2) if str1[i] != str2[j] then put matrix element as 0 3) if str1[i] == str2[j] then put matrix element as 1 … Continue reading

Posted in Algorithms | Leave a comment

Generate Prime Numbers in the 1..x range

Generate Prime Numbers in the 1..x range. http://leetcode.com/2010/04/finding-prime-numbers.html /* Generate a prime list from 0 up to n, using The Sieve of Erantosthenes param n The upper bound of the prime list (including n) param prime[] An array of truth … Continue reading

Posted in Algorithms | Leave a comment