In JavaScript, adding a method (function) to a constructor is different from adding a method to a regular object. To add a method to a constructor, we need to define it inside the constructor or in its prototype (using which JavaScript objects inherit features from one another). We can create an object in the following ways in JavaScript: Using the function Constructor (older way): function person(){ } const p = new person(); Using ES6 Class Syntax (i.e., modern way): class person{ constructor(){} } const p = new person(); Let's see the various ways to add ... Read More
An array in C/C++ is a fixed-size sequential collection of elements of the same data type where all the elements are stored in the contiguous memory allocation. If an array is accessed out of bounds then an undefined behavior will occur in C/C++, unlike Java where an exception such as java.lang.ArrayIndexOutOfBoundsException will occur. Accessing Out of Bound Memory Accessing out-of-bounds memory in an array means we are trying to access the array index outside its valid range size (i.e., index = array size). It returns any garbage value in the output. Example In ... Read More
In this article, we are given an array of integers. Our task is to write a program to calculate the maximum triplet sum in the given array, i.e., find the set of three elements whose sum is maximum. Input Output Scenario Consider the following input and output scenario where we have calculated the sum of each triplet and then returned the maximum sum of the triplet in the array: Input: arr = {4, 6, 1, 2} Output: Maximum triplet sum: 12 Here is an explanation of the above example: All ... Read More
The Quartan primes are prime numbers that can be represented as x^4 + y^4. Where x, y > 0. Some Quartan prime numbers are {2, 17, 97, …}.In this article, we will learn how to check whether a number is Quartan Prime or not in C++. Consider the following input and output scenarios to understand the concept better: Scenario 1 Input: 17 Output: The number is Quartan Prime Explanation Here, we can represent the given number in the form of x^4 + y^4; (1)^4 + (2)^4 => 1 + 16 = 17. Scenario 2 Input: 12 Output: The number ... Read More
The Hankel matrix is a square matrix, in which each ascending skew-diagonal or anti-diagonal (from top-right to bottom-left) elements are constant. For example a matrix name M with size 5x5 is given below − 1 2 3 4 ... Read More
In this problem, we are given two unsigned numbers, and we need to add them using bits in C++. Bits are binary digits that can be either 0 or 1. Unsigned numbers are positive numbers represented by these bits. To add two unsigned numbers, we add their bits one by one using binary addition rules. Binary addition works like decimal addition, but with simpler rules: 1 + 0 = 1 0 + 1 = 1 0 + 0 = 0 1 + 1 ... Read More
In this problem, we are given two binary strings, and we need to find their sum and return the result as a binary string. A binary string is a string that contains only the characters '0' and '1', where 0 and 1 are binary numbers. While adding two binary numbers, we follow the binary addition rules given below - 1 + 0 = 1 0 + 1 = 1 0 + 0 = 0 1 + 1 = 0 with a carry of 1 ... Read More
In C++, both arrays and vectors are used to store elements, but the main difference is that arrays have a fixed size and cannot be changed once initialized. Whereas, vectors are dynamic, i., e we can change their size during runtime. In this article, we'll look at the advantages of using vectors over arrays in C++. Here's how we declare an array and a vector in C++: // Declaring an array int arr[5]; // Fixed-size array of 5 integers // Declaring a vector #include std::vector vec; // Dynamic vector of integers Advantages of ... Read More
In a statically typed language such as C++, type specifiers are keywords that are used to define the type of data that given variables will hold. There are two types of type specifiers: built-in and user-defined type specifiers. Built-in Type SpecifiersThe built-in type specifiers are the basic and predefined data types provided by C++, such as int, float, char, signed, unsigned, short, long, etc. int myNumber = 42; In this given statement, the "int" is a type specifier, which states that the variable "myNumber" can only store integer values or numeric data types. There exist a lot of built-in type specifiers in C++ ... Read More
4SUM ProblemThe 4Sum is one of the problem variations in which we need to find the number of quadruplets present in the array such that their sum is equal to the given target. We are given an array of n integers called nums and a target value, and we have to find the number of index quadruplets (i, j, k, l) where i, j, k, and l are all indices in the range 0 to n - 1, such that they satisfy the condition: nums[i] + nums[j] + nums[k] + nums[l] = target Scenario 1 Inputs: arr= [-1, 0, 1, 2, ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP