If we specify the negative value of the second argument then the digits before the decimal point would be deleted and rounded off. The number of digits to be deleted depends upon the value of the negative second argument. Following examples will demonstrate the change, depending upon the negative value of the second argument, in the output of ROUND() function.mysql> Select ROUND(1789.456, -1); +--------------------+ | ROUND(1789.456, -1) | +--------------------+ | 1790 | +--------------------+ 1 row in set (0.00 sec) The query above returns 1790 because the first digit (which is to be deleted ... Read More
Problem statementGiven that integers are read from a data stream. Find median of elements read so for in an efficient wayAfter reading 1st element of stream - 10 -> median - 10After reading 2nd element of stream - 10, 20 -> median - 15After reading 3rd element of stream - 10, 20, 30 -> median - 20, so on...Algorithm1. Use a max heap on left side to represent elements that are less than effective median, and a min heap on right side to represent elements that are greater than effective median 2. After processing an incoming element, the number ... Read More
Problem statementMean is the average of the given data set calculated by dividing the total sum by the number of values in the data set.Mode of a data set is the value that appears most frequently in a series of dataIf our dataset is {1, 2, 3, 4} then mean value is − (1 + 2 + 3 + 4) / 4 = 2.5If our dataset is {1, 2, 3, 4, 1, 1, 1, 1} then mode value is − 1 as it appears 5 times.ExampleFirst, create a table −CREATE TABLE NUMBERS ( value INT )Insert data into the ... Read More
A JList is a subclass of JComponent class that allows the user to choose either a single or multiple selections of items. A JList can generate a ListSelectiionListener interface and it includes one abstract method valueChanged(). We can display a value when an item is selected from a JList by implementing MouseListener interface or extending MouseAdapter class and call the getClickCount() method with single-click event (getClickCount() == 1) of MouseEvent class.Exampleimport javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.*; public class JListItemSeletionTest extends JFrame { private JList list; private JScrollPane jsp; private Vector data; public JListItemSeletionTest() { setTitle("JListItemSeletion Test"); ... Read More
Problem statementGiven a range [L, R], we need to find two integers in this range such that their XOR is maximum among all possible choices of two integersIf the given range is L = 1 and R = 21 then the output will be 31 as − 31 is XOR of 15 and 16 and it is maximum within range.Algorithm1. Calculate the (L^R) value 2. From most significant bit of this value add all 1s to get the final resultExample#include using namespace std; int getMaxXOR(int L, int R){ int LXR = L ^ R; int msbPos = ... Read More
Problem statementGiven a binary tree, write a function to get the maximum width of the given tree. The width of a tree is the maximum of widths of all levels.Consider below tree − 10 / \ 7 4 / \ \ 9 2 1 / \ 2 5 1. Width at level 1: 1 2. Width at level 2: 2 3. Width at level 3: 3 4. Width at level 4: 2 For above tree answer is 3.Algorithm1. Use ... Read More
Problem statementGiven a string consisting of only A’s and B’s. We can transform the given string to another string by toggling any character. Thus many transformations of the given string are possible. The task is to find the Weight of the maximum weight transformation.Weight of a sting is calculated using below formula −Weight of string = Weight of total pairs + weight of single characters - Total number of toggles.Two consecutive characters are considered a pair only if they are different.Weight of a single pair (both characters are different) = 4Weight of a single character = 1If the input string ... Read More
A JTable is a subclass of JComponent class and it can be used to create a table with information displayed in multiple rows and columns. When a value is selected from a JTable, a TableModelEvent is generated, which is handled by implementing a TableModelListener interface. We can add or insert a radio button to a JTable cell by customizing the TableCellRenderer interface and the DefaultCellEditor class.Exampleimport java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.table.*; public class JTableRadioButtonTest extends JFrame { private DefaultTableModel dtm; private ButtonGroup bg; private JTable table; private JScrollPane jsp; public JTableRadioButtonTest() { setTitle("JTableRadioButton Test"); ... Read More
As we know that with the help of SHOW DATABASES statement we can see the list of MySQL databases. Similarly, we can use SHOW SCHEMAS as the synonym of SHOW DATABASES to get the list of databases.Examplemysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | gaurav | | mysql | | performance_schema | | query | | query1 | | sys | | tutorials | +--------------------+ 8 rows in set (0.07 sec) mysql> SHOW SCHEMAS; +--------------------+ | Database | +--------------------+ | information_schema | | gaurav | | mysql | | performance_schema | | query | | query1 | | sys | | tutorials | +--------------------+ 8 rows in set (0.00 sec)
As we know that COALESCE() function returns first non-NULL value from the list of values. The following IF-THEN-ELSE statement is equivalent to COALESCE() function.IF value1 is not NULL THEN output = value1; ELSIF value2 is not NULL THEN output = value2; ELSIF value3 is not NULL THEN output = value3; . . . ELSIF valueN is not NULL THEN output = valueN; ELSE output = NULL; END IF;
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP