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
Page 13 of 81
Print k different sorted permutations of a given array in C Program.
Given an array containing N integers, the challenge is to print k different permutations of indices such that the values at those indices form a non-decreasing sequence. Print -1 if it is not possible. Syntax void findSortedPermutations(int arr[], int n, int k); Algorithm The approach works by sorting the array while keeping track of original indices. If any two consecutive elements are equal, they can be swapped to generate different permutations − Create pairs of (value, original_index) for each array element Sort the pairs by value to get the first permutation Count ...
Read MorePrint index of columns sorted by count of zeroes in the Given Matrix in C Program.
Given a matrix of size NxM where N is the number of rows and M is the number of columns, we need to print the column indices sorted by the count of zeros in each column. This means we first count zeros in each column, then sort the columns based on these counts, and finally print the column indices (1-based indexing). For example, if column 1 contains 1 zero, column 2 contains 0 zeros, and column 3 contains 2 zeros, the result should be − 2 1 3 (sorted by zero count: 0, 1, 2). Syntax ...
Read MorePrint the corner elements and their sum in a 2-D matrix in C Program.
Given a 2D matrix, the challenge is to find and print the corner elements along with their sum. In a matrix, corner elements are located at the four corners: top-left, top-right, bottom-left, and bottom-right positions. For a matrix mat[r][c] with rows from 0 to r-1 and columns from 0 to c-1, the corner elements are: mat[0][0], mat[0][c-1], mat[r-1][0], and mat[r-1][c-1]. The task is to extract these corner elements and calculate their sum. Syntax // Corner elements of a matrix mat[r][c] mat[0][0] // Top-left corner mat[0][c-1] ...
Read MorePrint the balanced bracket expression using given brackets in C Program
Given four variables a, b, c, d with predefined values that represent different types of bracket pairs. The task is to use all the given brackets and print a balanced bracket expression using these bracket types. Where variables represent − a for (( b for () c for )( d for )) If we cannot form a balanced bracket expression then print "can't be formed". In case of multiple valid answers, we can print any of them. Syntax void print(int a, int b, int c, int d); Algorithm To ...
Read MorePrint the last occurrence of elements in array in relative order in C Program.
Given an array with elements and the task is to print the last occurrences of the given elements in the list. Here we not only have to remove the duplicate elements but also we have to maintain the order of the occurrences of the elements in an array as per the last time they have occurred. For example, if we have an array of 6 elements containing some duplicate values i.e., {1, 3, 2, 3, 1, 2}, the result should be in the form of 3 1 2. Syntax void printLastOccurrence(int arr[], int n); ...
Read MorePrint reverse of a Linked List without extra space and modification in C Program.
The task is to print the nodes of a linked list in reverse order without using extra space and without modifying the original linked list. This approach maintains O(1) space complexity by counting nodes and accessing them by position rather than using recursion or additional data structures. 10 21 33 42 89 ...
Read MorePrint the string after the specified character has occurred given no. of times in C Program
In C programming, we often need to extract a substring after a specific character has occurred a certain number of times. This task involves scanning through a string and printing all characters after the nth occurrence of a specified character. Syntax for (i = 0; i < string_length; i++) { if (count > 0) { if (string[i] == target_char) { count--; } ...
Read MoreC Program for Print the pattern by using one loop
In C programming, printing patterns using a single loop is an interesting challenge that demonstrates the creative use of loop control statements like continue. This approach combines the functionality of nested loops into one loop by manipulating loop variables and using conditional statements. Syntax for (initialization; condition; ) { // Logic with continue statement // Manual increment of loop variable } Algorithm START Step 1 → Declare variables i and j to 0 with number of rows n = 6 Step 2 → Loop For i=1 and i
Read MorePrint triplets with sum less than or equal to k in C Program
Given an array with a set of elements, the task is to find all triplets (sets of exactly three elements) having sum less than or equal to a given value k. Input − arr[] = {1, 2, 3, 8, 5, 4}, k = 10 Output − triplets → {1, 2, 3} {1, 2, 5} {1, 2, 4} {1, 3, 5} {1, 3, 4} {1, 5, 4} {2, 3, 5} {2, 3, 4} Syntax for (i = 0; i < size-2; i++) { for (j = i+1; j < size-1; j++) { for (k = j+1; k < size; k++) { if (arr[i] + arr[j] + arr[k]
Read MorePrint longest palindrome word in a sentence in C Program
In C programming, finding the longest palindrome word in a sentence involves parsing individual words and checking if they read the same forwards and backwards. A palindrome is a word that remains identical when its characters are reversed. What is a Palindrome? A palindrome is a word or sequence that reads the same backward as forward. For example, "malayalam" is a palindrome because reversing it gives "malayalam" − the same word. Examples of palindromes: radar, level, madam, racecar Syntax int isPalindrome(char word[], int start, int end); void findLongestPalindrome(char sentence[]); Algorithm The ...
Read More