Finding Middlemost Node of a Linked List in JavaScript

AmitDiwan
Updated on 23-Apr-2021 09:44:07

155 Views

ProblemWe are required to write a JavaScript function that takes in the head of a linked list as the first and the only argument.Our function should return the value stored in the middlemost node of the list. And if there are two middlemost nodes, we should return the second one of them.For example, if the list is like this:Input[4, 6, 8, 9, 1]Outputconst output = 8;Following is the code:Exampleclass Node {    constructor(data) {       this.data = data;       this.next = null;    }; }; class LinkedList {    constructor() {       this.head = ... Read More

Balancing Two Arrays in JavaScript

AmitDiwan
Updated on 23-Apr-2021 09:41:06

421 Views

ProblemWe are required to write a JavaScript function that takes in two arrays of numbers, arr1 and arr2, as the first and the second argument.The sum of elements in arr1 and arr2 are different. Our function should pick one element from the first array and push it in the second array and pick one element from the second array and push it in the first array such that the sum of the elements of both the arrays become equal. We should return an array of these two elements.For example, if the input to the function isInputconst arr1 = [1, 2, ... Read More

Maximum Subarray Sum in Circular Array Using JavaScript

AmitDiwan
Updated on 23-Apr-2021 09:11:28

228 Views

ProblemWe are required to write a JavaScript function that takes in an array of integers, arr, as the first and the only argument.We can consider this array arr to be a circular array, which means the last element of the array will be followed by the first. Our function should find and return the maximum possible sum of a non-empty subarray of arr.For example, if the input to the function isInputconst arr = [2, -2, 3, -1];Outputconst output = 4;Output ExplanationBecause the desired subarray is [3, -1, 2]Example Live Democonst arr = [2, -2, 3, -1]; const maxSubarraySumCircular = (arr = ... Read More

Placing Integers at Correct Index in JavaScript

AmitDiwan
Updated on 23-Apr-2021 07:43:05

155 Views

ProblemWe are required to write a JavaScript function that takes in a string, str, which consists of only ‘[‘ or ‘]’. Our function is supposed to add the minimum number of square brackets ( '[' or ']', and in any positions ) so that the resulting bracket combination string is valid. And lastly, we should return the smallest number of brackets added.For example, if the input to the function isInputconst str = '[]]';Outputconst output = 1;Output ExplanationBecause, if we add ‘[‘ to the starting, the string will be balanced.Exampleconst findAdditions = (str = '') => {    let left = 0 ... Read More

Finding Minimum Flips in a Binary String Using JavaScript

AmitDiwan
Updated on 23-Apr-2021 07:35:10

223 Views

Monotonically Increasing String:A string of '0's and '1's is monotonically increasing if it consists of some number of '0's (possibly 0), followed by some number of '1's (also possibly 0.)ProblemWe are required to write a JavaScript function that takes in a binary string, str, as the first and the only argument.We can flip any ‘0’ to ‘1’ or any ‘1’ to ‘0’ present in the string. Our function should return the minimum number of flips to make S monotonically increasing.For example, if the input to the function isInputconst str = '00110';Outputconst output = 1;Output ExplanationBecause if we flip the last ... Read More

Binary Subarrays with Desired Sum in JavaScript

AmitDiwan
Updated on 23-Apr-2021 07:26:00

131 Views

ProblemWe are required to write a JavaScript function that takes in a binary array, arr, as the first argument, and a number, target, as the second argument.Our function is supposed to count the number of subarrays that exists in the array arr, the sum of whose elements is equal to count. We should finally return this count.For example, if the input to the function isInputconst arr = [1, 0, 1, 0, 1]; const target = 2;Outputconst output = 4;Output ExplanationBecause the desired subarrays are:[1, 0, 1][1, 0, 1, 0] [0, 1, 0, 1] [1, 0, 1]Example Live Democonst arr = [1, ... Read More

Difference Between RGB and CMYK

AmitDiwan
Updated on 23-Apr-2021 07:05:49

334 Views

In this post, we will understand the difference between RGB and CMYK colour schemes −RGB Colour SchemeIt is used with digital works.The primary colours in this scheme are ‘Red’, ‘Green’, and ‘Blue’.It is an additive Type Mixing scheme.The colours of this scheme’s images are more vibrant.It has a wide range of colours in comparison to CMYKThe file formats to work with this colour scheme are JPEG, PNG, and GIF.CMYK Colour SchemeIt is used with print works.The primary colours in this scheme are ‘Cyan’, ‘Magenta’, ‘Yellow’, and ‘Black’.It is a subtractive Type Mixing scheme.The colours of this scheme’s images are less ... Read More

Difference Between USART and UART

AmitDiwan
Updated on 23-Apr-2021 06:58:46

2K+ Views

In this post, we will understand the difference between USART and UART modes −USART (Universal Synchronous/Asynchronous Receiver/Transmitter)The half-duplex mode is used.The speed of USART is more in comparison to UART.It uses data signals as well as clock to work.The data is transmitted in the format of blocks.It can work similar to UART.It is more complex in comparison to UART.The receiver doesn’t require to know the baud-pace of the transmitter.This is because it gets information by the master and the clock signal.The data is transmitted at a definite (specific) rate.UART (Universal Asynchronous Receiver/Transmitter)It uses full-duplex mode.Its speed is less in comparison ... Read More

Difference Between Cache and Cookies

AmitDiwan
Updated on 23-Apr-2021 06:48:33

1K+ Views

In this post, we will understand the difference between cache and cookies −CacheIt helps store the content of the website which is used frequently.The content of the website is stored in the browser.It expires manually.It consumes more space.Different types of cache are: Browser cache and proxy cache.It stores contents like HTML pages, images, JavaScript, CSS.It doesn’t send a response with a request.CookiesIt helps store the user’s choice.The contents of the cookie are stored in both the server and browser.It expires automatically.It consumes less space.Different types of cookies are: Transient cookies and persistent cookies.A cookie stores the contents such as browsing ... Read More

Difference Between WordPress.com and WordPress.org

AmitDiwan
Updated on 23-Apr-2021 06:46:40

146 Views

In this post, we will understand the difference between wordpress.com and wordpress.org −Wordpress.orgIt is also known as the real WordPress.It is open source, and can be used by anyone.A domain name and a web hosting service is required to use this.It is also referred to as self-hosted WordPress.User has full control of the website.WordPress plugins that are free, or paid can be added to the website.The website and all of its data is owned by the user.Google analytics can be used to perform customized analytics.Advertisements can be run and revenue can be generated.User has to keep several backups of the ... Read More

Advertisements