Skip to main content

Posts

Featured

Coding Interview Questions set 4

Let's begin with set 4,9)Find the majority Element?Given an array of size n, find the majority element. The majority element is the element that appears more than  n/2 times.Assumptions:You may assume that the array is non-empty and the majority element always exists in the array.Example 1:
Input: [4,2,4]Output: 4
Example 2:
Input: [3,3,1,1,1,3,3]Output: 3
Solution:var majorityElement = function(nums) {var obj = {};for(var i = 0; i < nums.length; i++){obj[nums[i]] = obj[nums[i]] + 1 || 1;if(obj[nums[i]] > nums.length / 2) {return nums[i];} }};
Logic:We have used an object map for maintaining the count.         You may also like this articles:Coding Interview Set 1Coding Interview Set 2. Coding Interview Set 3

10)Check if two strings are an anagram of each other?2 words are anagram if 2nd word is formed by rearranging the letters from 1st word.  
Example 1:Input: s = "anagram", t = "nagaram"Output: trueExample 2:
Input: s = "rat", t = "car"Outpu…

Latest Posts

Javascript interview questions set 2

Coding Interview Questions Set 3

Css Interview Questions Set 1

Coding Interview Questions Set 2

Coding Interview Questions Set 1

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

2 JavaScript Interview Questions that you must know.

4 html interview questions that you must know.

Javascript/Node.js: 2 Features that you might not know.

Node.js: Bundling your Node.js application to single executable for Windows.