Skip to main content


Coding Interview Questions Set 3

For previous  questions and answers please refer to   Coding Interview Questions Set 1  and Coding Interview Set 2 . Let's begin with set 3, 7)How to reverse a singly linked list? a)Simple recursive solution: function reverseList(head) {     if (!head || ! {         return head;     }     var newHead = reverseList(; = head; = null;     return newHead; } b)Iterative solution: function reverseList(head) {     var prev = null;     while (head) {         var next =; = prev;         prev = head;         head = next;     }     return prev; } 8)Given a column title, return its corresponding column number. (Asked in Microsoft) Write a function that accepts a string s. Constraints: 1 <= s.length <= 7 s consists only of uppercase English letters. s is between "A" and "FXSHRXW". For example:     A -> 1     B -> 2     C -> 3     .

Css Interview Questions Set 1

Let's begin with set 1, 1)What is CSS box model? The CSS box model is essentially a box that wraps around every HTML element. It consists of: margins, borders, padding, and the actual content. The image below illustrates the box model: Explanation: Content - The content of the box, where text and images appear. Padding - Clears an area around the content. The padding is transparent Border - A border that goes around the padding and content. Margin - Clears an area outside the border. The margin is transparent. 2)What are selectors in CSS? In CSS, selectors are patterns used to select the elements you want to style. Here are few most used selectors, a).class : Ex:.intro Selects all elements with class="intro". b).class1.class2 Ex: .name1.name2 Selects all elements with both name1 and name2 set within its class attribute. c)#id  Ex:#firstname Selects the element with id="firstname". d)element  Ex:p Selects all <p> ele

Coding Interview Questions Set 2

For first 3 questions and answers please refer to   Coding Interview Questions Set 1 . Let's begin with set 2, 4)For a given binary tree find the depth/height of a binary tree. Solution : var depth= function(root) {     if(root === undefined || root===null){         return 0;     }     return Math.max(depth(root.left),depth(root.right)) + 1; }; Logic: Divide and conquer. 5)In a given array move all the 0 's to the end without disturbing order of non-zero elements.  Solution: var moveZeroes = function(nums) {          for(var i = nums.length;i--;){         if(nums[i]===0){             nums.splice(i,1)             nums.push(0);         }     } }; Logic: Remove each 0 and add 0 at the end of the array. 6)Calculate the sum of 2 integers without using + and - operator. Solution: var add = function(a, b) {     let carry;     while(b) {         carry = a & b;         a ^= b;         b = carry << 1;     }     return a; }; Logic:

Coding Interview Questions Set 1

From this article, I will be sharing with you all a series of articles on coding interview questions. So please stay connected for the latest set of questions. It will be a good brainstorming exercise and will also prepare you for coding interviews and will definitely boost your confidence. So let's start, 1)Reverse of a string with only O(1) extra memory. Solution: var reverse = function(string) {     let result = ''     for(let i= string.length -1; i >= 0; i--){         result += string[i];     }     return result; }; 2)Fizz Buzz: Write a program that will accept a number n and will output number till n but for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. For numbers which are multiples of both three and five output “FizzBuzz”. Solution: var fizzBuzz= function(n) {     const arr=[]     for(i=1; i<=n; i++){         if(i%15===0) arr.push("FizzBuzz")         else

Node.js: Downloading a xml file from given url and reading its data elements.

In this article, we will see how we can download an XML file from a given URL and then access its elements. This can be used in many cases, for example, scraping data from a site which has data in the XML file or multiple files. The article is pretty short and most of it is just self-explanatory code. Also nowadays, you can get a lot of freelance jobs in data scrapping as data is the new oil today so this might be helpful. So let's begin with the code, var fs = require('fs') var https = require('https');//For accessing https url we need this module instead of http. var xml2js = require('xml2js');//Required for xml parsing. var file_name = 'data.xml'//This will be the name of file we will be generating. var DOWNLOAD_DIR =__dirname+'/'; //This function reads data from URL and writes data into new file //with respect to the given name and directory path. function download(){  var file_url='

2 JavaScript Interview Questions that you must know.

In this article, we will see in detail a couple of interview questions in Javascript. 1)What is a deep copy and Shallow copy? Shallow copy:  In shallow copy, all the top-level primitives get a copy excluding objects which are still connected to the original value. Note: If the array is of strings or number it gets copied but in case of an array of objects it is still connected to the original value. Primitive data types include the following: Number — e.g. 1 String — e.g. 'Hello' Boolean — e.g. true undefined null Example: var tshirt={     size:170,     sizeInLocal:'L',     sizeAvailable:{     'm':"Available"      } } Lets make a copy a shallow copy of tshirt object: var tshirt1=Object.assign({}, tshirt) tshirt1.sizeAvailable.m="NotAvailable"//Here tshirt.sizeAvailable.m will also become NotAvailable . tshirt1.size=150;//Only value of tshirt1.size is changed and not tshirt.size as size is of primitive type.  

4 html interview questions that you must know.

In this article, we will see some HTML interview questions I faced during interviews. So let's start, 1)What is Doctype in html? All HTML documents must start with a <!DOCTYPE> declaration. The declaration is not an HTML tag. It is an "information" to the browser about what document type to expect. In HTML 5, the declaration is simple: <!DOCTYPE html> Note: The <!DOCTYPE> declaration is NOT case sensitive. 2)What is DOM in html? The DOM (Document Object Model)is a W3C (World Wide Web Consortium) standard. The DOM defines a standard for accessing documents: The HTML DOM is a standard object model and programming interface for HTML. When a web page is loaded, the browser creates a Document Object Model of the page. It defines: The HTML elements as objects The properties of all HTML elements The methods to access all HTML elements The events for all HTML elements In other words: The HTML DOM is a standard for how to get, chan