It is an algorithm that searches for an element in a sorted array, and it follows a Divide and Conquer algorithmic model. Dictionary is the best example for Binary Search, since the words are in alphabetical order we don’t need to search each page by page for a word. Just, we will compare the word…
In java, join() methods allows one thread to wait for the complete execution of other thread. Consider there are two threads T1 & T2, currently thread T1 is executing, and we invoked join() method on T2 then execution of thread T1 is paused and waits for the completion of execution of Thread T2 and then…
Question: Given an array of integers nums containing n + 1 integers where each integer is in the range [1, n] inclusive. There is only one repeated number in nums, return this repeated number. You must solve the problem without modifying the array nums and uses only constant extra space. Example 1: Input: nums =…
Create Custom Annotation: In java, creating an annotation is @interface is used to create an Annotation. public @interface MyAnnotation{ } We can also define methods inside an annotation. public @interface MyAnnotation{ int value(); } Note: The methods of an annotation should adhere to the following rules: Method declaration should not have any parameters Method declaration should not…
There is no official method to kill a thread in Java. Stopping a thread is entirely managed by the JVM. Although Java provides several ways to manage the thread lifecycle such as a start(), sleep(), stop() (deprecated in Java 1.1), etc. but does not provide any method to kill a thread and free the resources cleanly. Oracle specified the reason for deprecating the…
How to concatenate multiple rows of a column in a table into a single column? I have to concatenate multiple rows to a single column. For example, consider the below teacher’s table. The above table is a normalized table containing the subjects and teacher ID. We will denormalize the table, by concatenating the subjects of…
In this article, I am going to show different ways of deleting duplicating records from the table. It is a common question in interviews which is asked frequently. Consider the following table with rows as an example: Table Name: Products ProductId Price ————— 1 10 1 10 2 20 3 30 3 30 Here, assume…
Interview Question: In one of my project, I got a requirement to group N consecutive rows and find the min, max and sum of values in each group. In this article, I will show you how to do aggregation on N successive rows. Let’s take the sales table as an example. The data in the…
Self Join: By definition, a self join query is a query in which the table is joined to itself. Self joins are written in cases where there is parent child relationships in the data. Let’s take the classic example of employees table. We have to write a self join query to find out the immediate…
To delete the remote branch: git push -d origin <branch-name> Or git push origin :<branch-name> Executive Summary git push -d <remote_name> <branchname> git branch -d <branchname> Note: In most cases, <remote_name> will be origin. Delete Local Branch To delete the local branch use one of the following: git branch -d <branch_name> git branch -D <branch_name> The -d option is an alias for –delete, which…