Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Sunidhi Bansal
809 articles
Print elements that can be added to form a given sum
This program finds and prints elements from a given array that can be added together to form a specified sum. The algorithm uses a greedy approach where it iterates through the array and selects elements that don't exceed the remaining sum value. Algorithm The greedy algorithm works as follows − START STEP 1 → Take number of elements and array values from user STEP 2 → Take the target sum from user STEP 3 → For i = 0 to n-1 STEP 4 → If (current_sum - array[i]) >= 0 then ...
Read MoreContent Spoofing
Content Spoofing is a type of attack where malicious programmers present a fake website as legitimate to users through text injection or HTML injection. When web applications fail to properly validate user-supplied data, attackers can inject additional parameters that modify the displayed content, leading users to pages that appear authentic but are designed to steal sensitive information. Content spoofing attacks exploit insufficient input validation and output encoding in web applications. The attacker manipulates URL parameters or form data to alter the content displayed to users, creating convincing replicas of legitimate pages to harvest credentials, personal information, or financial data. ...
Read MoreC Program to Redeclaration of global variable
In C programming, variable redeclaration refers to declaring a variable more than once in the same scope. The behavior of redeclaration varies between global and local variables, and differs between C and C++. Understanding these differences is crucial for avoiding compilation errors. Syntax // Global variable redeclaration int var; int var; // Allowed in C without initialization // Local variable redeclaration int main() { int var; int var; // Not allowed in C } Global Variable Redeclaration Without Initialization C allows ...
Read MoreMaximum distinct lines passing through a single point in C
In computational geometry, finding the maximum number of distinct lines passing through a single point is a common problem. Given N lines defined by pairs of coordinates (x1, y1) and (x2, y2), we need to find how many lines with different slopes can pass through a single point. Syntax int maxDistinctLines(int n, int x1[], int y1[], int x2[], int y2[]); Approach We represent each line using the slope formula y = mx + c, where m is the slope calculated as − For non-vertical lines: slope = (y2 - y1) / (x2 ...
Read MoreMaximum given sized rectangles that can be cut out of a sheet of paper in C
We are given the dimensions of a sheet of paper, its Length L and Breadth B. Also, we are given the dimensions of a smaller rectangle, its length l and breadth b. The goal is to find the maximum number of smaller rectangles that can be cut out of the sheet of paper. We will follow these steps − First, try horizontal alignment: divide the sheet length L by rectangle length l, and sheet breadth B by rectangle breadth b, then multiply to get the count. Then try vertical alignment (rotate the rectangle 90°): divide sheet length ...
Read MoreMaximum number of candies that can be bought in C
We are given an array of candies[] of length stored in 'size'. Each element candies[i] has a number for candies of type i. The goal is to buy as many candies as possible for any amount of money. The conditions are as given − If you purchase X[i] of type i (0
Read MoreMaximum number of 2×2 squares that can be fit inside a right isosceles triangle in C
We are given a right isosceles triangle where we need to find the maximum number of 2×2 squares that can fit inside it. An isosceles triangle has two sides of equal length, and in a right isosceles triangle, the base and height are perpendicular and equal to each other. Base Height The key insight is that from the corner triangular areas, we need to subtract ...
Read MoreCount number of 1s in the array after N moves in C
We are given an array of size N. The array has all 0's initially. The task is to count the number of 1's in the array after N moves. Each Nth move has a rule associated with it − 1st Move − Change element at positions 1, 2, 3, 4... 2nd Move − Change element at positions 2, 4, 6, 8... 3rd Move − Change element at positions 3, 6, 9, 12... In each move, we flip the elements (0 becomes 1, 1 becomes 0) at the specified positions. Let's understand with examples. Syntax ...
Read MoreMaximum binomial coefficient term value in C
In C, finding the maximum binomial coefficient term for a given positive integer 'N' involves calculating all binomial coefficients nCr and determining the largest value among them. The binomial coefficient series is nC0, nC1, nC2, ..., nCr, ..., nCn-2, nCn-1, nCn. Syntax nCr = n! / (r! * (n - r)!) For N=4: 4C0=1, 4C1=4, 4C2=6, 4C3=4, 4C4=1. Maximum coefficient is 6. For N=5: 5C0=1, 5C1=5, 5C2=10, 5C3=10, 5C4=5, 5C5=1. Maximum coefficient is 10. Method 1: Using Pascal's Triangle Approach This method builds Pascal's triangle using dynamic programming to calculate binomial ...
Read MoreMaximize the difference between two subsets of a set with negatives in C
We are given an array of positive and negative integers. The task is to find the maximum difference between two subsets where one contains positive numbers and the other contains negative numbers. The maximum difference is achieved by taking all positive numbers in one subset and all negative numbers in the other subset, then calculating (sum of positives) − (sum of negatives). Since subtracting negatives effectively adds them, we can convert all negatives to positives and sum all elements. Syntax int maximizeSubsetDifference(int arr[], int n); Example Input and Output Input − Arr[] = { ...
Read More