Programming Articles

Page 1119 of 2547

How to remove Lua table entry by its key?

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

Let’s consider an example where we would like to remove a Lua table entry. The table itself behaves like a hashmap, where it has several key value pairs, and we would like to remove an entry from that table on the basis of the key.Lua library does provide a function that we can use for our specific case. The function is table.remove() and it takes two arguments, the first argument is the name of the table and the second argument is the key that we want to remove.ExampleConsider the example shown below −local mapone = { [1] = 10, [2] ...

Read More

Largest permutation after at most k swaps in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 710 Views

In this tutorial, we are going to write a program that finds the largest permutation after at most k swaps.Let's see the steps to solve the problem.Initialise the array.Initialise an array to store the index with size n + 1.Iterate over the array and store the index of each element in the position array.Write a loop that iterate till n and k is greater than 0.Store the position of n - i element in a temp variable.Update position of current element arr[i] with position[n - i].Update the position position[n - i] with current index i.Swap the current element arr[i] with ...

Read More

Largest set with bitwise OR equal to n in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 153 Views

In this tutorial, we are going to write a program that finds the largest set with bitwise OR is equal to the given number n.Let's see the steps to solve the problem.Initialise the number n.Write a loop that iterates from 0 to n.If the i | n is equal to n, then add i to the result.Return the result.ExampleLet's see the code.#include using namespace std; void printBitWiseOrSet(int n) {    vector v;    for (int i = 0; i

Read More

Largest subarray having sum greater than k in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 457 Views

In this tutorial, we are going to write a program that finds the largest subarray have sum greater than k.Let's see the steps to solve the problem.Initialise the array.Iterate over the array and store sum at each index in a vector along with the index.Sort the above sums based on sum and index.Initialise an array to store the indexes.Write a loop that iterates till n.Update the values with min index of above indexes array and previous sums array index.Initialise sum to 0.Write a loop that iterates till n.Add current element to sum.If the sum is greater than k.The maximum subarray ...

Read More

Largest subarray with equal number of 0s and 1s in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 262 Views

Let's see the steps to complete the program.Initialise the array.Make all zeroes in the array to -1.Have a map an empty map to store the previous indexes.Initialise sum to 0, max length to 0 and ending index to -1.Write a loop that iterates till n.Add current element to sum.If the sum is equal to 0.Update the max length with i + 1.And ending index to i.If the sum is present in previous sums map and i - previousIndexes[sum] is greater than max length.Update the max length and ending index.Else add the sum to the previous indexes map.Print the starting index ...

Read More

How to use the Insert function in Lua Programming?

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

There are cases when we want to insert elements into a table. In Lua, the table library provides functions to insert elements into the table.The insert function usually takes two arguments, the first argument is usually the name of the table from which we want to insert the element to, and the second argument is the element that we want to insert.If there are three arguments passed to the insert function then the second argument denotes the position in the table where we want to insert the element at.Let’s explore different examples of the insert function.Syntaxinsert(x, element) or insert(x, pos, ...

Read More

Largest sum subarray with at-least k numbers in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 458 Views

Let's see the steps to complete the program.Initialise the array.Initialise max_sum array of size n.Find the max sum for every index and store it in max_sum array.Compute the sum of all the elements and store it in a variable sum.Write a loop that iterates from i = k to n.Add a[i] - a[i - k] to the sum.Update the result with max of result, sum.Update the result with max of result, sum + max_sum[i - k].ExampleLet's see the code.#include using namespace std; int getMaxSum(int a[], int n, int k) {    int maxSum[n];    maxSum[0] = a[0];    int currentMax ...

Read More

How to Use the Remove function in Lua programming?

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

There are cases when we want to remove an element from a table. In Lua, the table library provides functions to remove elements from the table.The remove function usually takes two arguments, the first argument is usually the name of the table from which we want to remove the element from, and the second argument is the position from which we want to remove the element from.Let’s explore different examples of the remove function.Syntaxtable.remove(x, pos)The x in the above example denotes the name of the table from which we want to remove the element from, and the pos identifier in ...

Read More

How to use the require function in Lua programming?

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

Lua offers a high-level function which we can use when we want to load and run libraries. This high-level function is named require function.The require function mainly targets the high level functions and keywords.The require function is a bit similar to the dofile function, but it has two key differences, the first one being that it searches for the file in a specified path and the second one is that it mainly focuses on to control whether the file is already running on the script or not.Syntaxrequire “module-name” // some codeHow Does the require Function Work in Lua?It is mainly ...

Read More

How does the event pattern work in .NET?

Akshay Khot
Akshay Khot
Updated on 11-Mar-2026 644 Views

Events are a simplified pattern that uses delegates. In C#, all delegates have the multicast capability, i.e., an instance of a delegate can represent not just a single method but a list of methods. For example −Exampledelegate int Transformer(int x); static void Main(){    Transformer perform = x =>{       int result = x * x;       Console.WriteLine(result);       return result;    };    perform += x =>{       int result = x * x * x;       Console.WriteLine(result);       return result;    };    perform(2); // prints ...

Read More
Showing 11181–11190 of 25,466 articles
Advertisements