Articles on Trending Technologies

Technical articles with clear explanations and examples

Python Program to Implement Queues using Stacks

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 442 Views

When it is required to implement a queue using a stack, a queue class can be defined, where two stack instances can be defined. Different operations can be performed on the queue that are defined as methods in this class.Below is a demonstration of the same −Exampleclass Queue_structure:    def __init__(self):       self.in_val = Stack_structure()       self.out_val = Stack_structure()    def check_empty(self):       return (self.in_val.check_empty() and self.out_val.check_empty())    def enqueue_operation(self, data):       self.in_val.push_operation(data)    def dequeue_operation(self):       if self.out_val.check_empty():          while not self.in_val.check_empty():   ...

Read More

Removing letters to make adjacent pairs different using JavaScript

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 199 Views

ProblemWe are required to write a JavaScript function that takes in a string that contains only ‘A’, ‘B’ and ‘C’. Our function should find the minimum number of characters needed to be removed from the string so that the characters in each pair of adjacent characters are different.ExampleFollowing is the code −const str = "ABBABCCABAA"; const removeLetters = (str = '') => {    const arr = str.split('')    let count = 0    for (let i = 0; i < arr.length; i++) {       if (arr[i] === arr[i + 1]) {          count += 1          arr.splice(i, 1)          i -= 1       }    }    return count } console.log(removeLetters(str));Output3

Read More

Comments in Dart Programming

Mukul Latiyan
Mukul Latiyan
Updated on 11-Mar-2026 487 Views

Comments are a set of commands that are ignored by the compiler. They are used in a scenario where you want to attach a note to your code or a section of code so that when you visit it later, you can recall it easily.The comment statements are usually ignored during the execution of the program.There are multiple types of comments in Dart, mainly these are −Single line commentsMulti-line commentsDocumentation commentsWe will explore all the above document types in this article.Single Line commentsSingle line comments make use of // (double forward slash). They extend up to a new line character.Syntax// ...

Read More

How to set the position of legend of a ggplot2 graph to left-top side in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 672 Views

To set the position of legend of a ggplot2 graph to left-top side in R, we can follow the below steps −First of all, create a data frame.Then, create a plot using ggplot2 with legend.After that, add theme function to the ggplot2 graph to change the position of legend.Create the data frameLet's create a data frame as shown below −> x y Grp df dfOn executing, the above script generates the below output(this output will vary on your system due to randomization) −          x          y     Grp 1   1.534536456  1.16096642 ...

Read More

Third smallest number in an array using JavaScript

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 627 Views

ProblemWe are required to write a JavaScript function that takes in an array of numbers of length at least three.Our function should simply return the third smallest number from the array.ExampleFollowing is the code −const arr = [6, 7, 3, 8, 2, 9, 4, 5]; const thirdSmallest = () => {    const copy = arr.slice();    for(let i = 0; i < 2; i++){       const minIndex = copy.indexOf(Math.min(...copy));       copy.splice(minIndex, 1);    };    return Math.min(...copy); }; console.log(thirdSmallest(arr));Output4

Read More

Changing second half of string number digits to zero using JavaScript

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 218 Views

ProblemWe are required to write a JavaScript function that takes in a string number as the only argument.Our function should return the input number with the second half of digits changed to 0.In cases where the number has an odd number of digits, the middle digit onwards should be changed to 0.For example −938473 → 938000ExampleFollowing is the code −const num = '938473'; const convertHalf = (num = '') => {    let i = num.toString();    let j = Math.floor(i.length / 2);    if (j * 2 === i.length) {       return parseInt(i.slice(0, j) + '0'.repeat(j));   ...

Read More

const keyword in Dart Programming

Mukul Latiyan
Mukul Latiyan
Updated on 11-Mar-2026 810 Views

Dart provides us with two ways in which we can declare variables with fixed values. One of them is by declaring a variable with a const keyword, and the other is by declaring the variable with a final keyword.It should be noted that both of them does provide an assurance that once a value is assigned to the variable with them, it won't change, but indeed they are slightly different from one another.constA variable that is declared using the const keyword cannot be assigned any other value. Also, the variable is known as a compile-time constant, which in turn means that ...

Read More

How to remove row that contains maximum for each column in R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 1K+ Views

To remove row that contains maximum for each column in R data frame, we can follow the below steps −First of all, create a data frame.Then, remove the rows having maximum for each column using lapply and which.max function.Create the data frameLet's create a data frame as shown below −> x1 x2 df dfOn executing, the above script generates the below output(this output will vary on your system due to randomization) −   x1 x2 1  9  10 2  1  9 3  8  9 4  7  6 5  4 10 6  4  7 7  8  8 8  5 13 9  4 ...

Read More

Maximum and Minimum K elements in Tuple using Python

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 1K+ Views

When it is required to find the maximum and minimum K elements in a tuple, the ‘sorted’ method is used to sort the elements, and enumerate over them, and get the first and last elements.Below is the demonstration of the same −Examplemy_tuple = (7, 25, 36, 9, 6, 8) print("The tuple is : ") print(my_tuple) K = 2 print("The value of K has been initialized to ") print(K) my_result = [] my_tuple = list(my_tuple) temp = sorted(my_tuple) for idx, val in enumerate(temp):    if idx < K or idx >= len(temp) - K:       my_result.append(val) ...

Read More

Constructors in Dart Programming

Mukul Latiyan
Mukul Latiyan
Updated on 11-Mar-2026 1K+ Views

Constructors are methods that are used to initialize an object when it gets created. Constructors are mainly used to set the initial values for instance variables. The name of the constructor is the same as the name of the class.Constructors are similar to instance methods but they do not have a return type.All classes in Dart have their own default constructor, if you don't create any constructor for a class, the compiler will implicitly create a default constructor for every class by assigning the default values to the member variables.We can create a constructor in Dart something like this −class ...

Read More
Showing 1251–1260 of 61,248 articles
« Prev 1 124 125 126 127 128 6125 Next »
Advertisements