Posts

Indian Penal Code Part 1

Image
The Indian Penal Code (IPC) is a comprehensive criminal code that applies to all citizens of India. It contains provisions related to a variety of crimes, including murder, theft, assault, fraud, and sedition. It is applicable within the territorial boundaries of India and also for offenses committed by Indians abroad.  For example, according to the Indian Penal Code Section 82: “Nothing is an offence which is done by a child under the age of twelve years”. This means that any act committed by a 12 year old in India will not be viewed as a criminal offence under Indian law. The Code of Criminal Procedure: (CrPC) is a substantive law that governs the criminal justice system in India. It contains provisions for the collection of evidence and enforcement of criminal laws. Specifically, it explains the procedure for prosecuting an offender, including arrest, examinations of witnesses, collection and analysis of evidence, and various other stages in between. The Code also includes provisio

New Tax Regime Calculator

Input Please enter your income Calculate </html

Diwali Data Structure Famous Problem

Image
Number of Islands   Given an   m x n   2D binary grid   grid   which represents a map of   '1' s (land) and   '0' s (water), return   the number of islands . An  island  is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water.   Example 1: Input: grid = [ ["1","1","1","1","0"], ["1","1","0","1","0"], ["1","1","0","0","0"], ["0","0","0","0","0"] ] Output: 1 Example 2: Input: grid = [ ["1","1","0","0","0"], ["1","1","0","0","0"], ["0","0","1","0","0"], ["0","0","0","1&q

Nodejs interview questions set 3

Image
  1)What is nonblocking io? Ans:  Non-blocking I/O operations allow a single process to serve multiple requests at the same time. Instead of the process being blocked and waiting for I/O operations to complete, the I/O operations are delegated to the system, so that the process can execute the next piece of code 2)Async await in foreach? Ans: Array.prototype.forEach is not designed for asynchronous code. (It was not suitable for promises, and it is not suitable for async-await.) For example, the following forEach loop might not do what it appears to do: const players = await this.getWinners(); // BAD await players.forEach(async (player) => {   await givePrizeToPlayer(player); }); await sendEmailToAdmin('All prizes awarded'); What's wrong with it? The promises returned by the iterator function are not handled. So if one of them throws an error, the error won't be caught. (In Node 10, if no unhandledrejection listener has been registered, that will cause the process to

MongoDB interview questions set 1

Image
  1)How to find the second highest salary ? var records = [ {salary : 100 . ..m, 00 }, {salary : 9000 }, {salary : 9000 }, {salary : 5000 }, {salary : 10000 }, ] let counts = await _db.collection( "salary" ).insertMany(records) Ans : Solution 1 let highest = await _db.collection( "salary" ).find().sort({salary :- 1 }).limit( 1 ).toArray(); let secondhighest = await _db.collection( "salary" ).find({salary : {$lt : counts[ 0 ].salary}}).sort({salary :- 1 }).limit( 1 ).toArray(); Solution 2 : step : 1 var sal = await _db.collection( "salary" ).distinct( "salary" ) output : [ 5000 , 9000 , 10000 , ] step : 2 9000 is the second - highest salary   2)How to find if the query for finding records uses an index or not?     let highest = await _db.collection("salaryy").find({itd:{$gte:0}}).sort({salary:-1}).explain('executionStats'); explain query will give all details

Coding interview set 9

Image
  Let's begin with set 9, 18) Write a logic that takes input as  EC:B0:8T:E4 and response should be "0C:B0:80:04". Wrong solution is already provided find the issue in that? let mac = 'EC:B0:8T:E4' const mapper = {     E: 0,     T: 0 } Wrong solution: var decoded = "" ; for ( let item of mac){ decoded = decoded + mapper[item] != undefined ? mapper[item] : item; } console.log(decoded); The issue with this solution: + vs. ?: In JavaScript, the + operator has higher precedence than the ?: operator. This means that concatenation will take place before the condition in a ternary is evaluated. This can lead to some strange results.  Note: operator associativity and precedence can change between languages. For example, in JavaScript the ?: operator is right-associative but it's left-associative in PHP. These same comparisons will produce different results between these languages. One of the correct solutions with () as it has higher precedence : va

Data structure problem 3: Implement a Stack With Minimum

Image
  Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. Implement the MinStack class: MinStack() initializes the stack object. void push(int val) pushes the element val onto the stack. void pop() removes the element on the top of the stack. int top() gets the top element of the stack. int getMin() retrieves the minimum element in the stack. Input ["MinStack","push","push","push","getMin","pop","top","getMin"] [[],[-2],[0],[-3],[],[],[],[]] Output [null,null,null,null,-3,null,0,-2] Explanation MinStack minStack = new MinStack(); minStack.push(-2); minStack.push(0); minStack.push(-3); minStack.getMin(); // return -3 minStack.pop(); minStack.top();    // return 0 minStack.getMin(); // return -2 Solution: var  MinStack =  function ( )  { this .elements = []; }; /** @param {number} x @return {void} */ MinStack.prototype.push = function ( x ) { this .element