Server Side Programming Articles

Page 901 of 2109

a.sort, sorted(a), np_argsort(a) and np.lexsort(b, a) in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 803 Views

Python provides built-in sorting functions (sorted(), list.sort()) and NumPy provides advanced sorting (np.argsort(), np.lexsort()) for working with arrays and multiple sort keys. sorted() Returns a new sorted list without modifying the original ? a = [9, 5, 3, 1, 12, 6] b = sorted(a) print("Sorted Array:", b) print("Original Array:", a) Sorted Array: [1, 3, 5, 6, 9, 12] Original Array: [9, 5, 3, 1, 12, 6] list.sort() Sorts the list in-place (modifies the original, returns None). Faster than sorted() since it doesn't create a copy ? a = ...

Read More

Absolute and Relative Imports in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 781 Views

In Python, when you need to access code from another file or package, you use import statements. There are two approaches − absolute imports (full path from the project root) and relative imports (path relative to the current file). How Python Resolves Imports When Python encounters an import statement, it searches in this order − Module cache − Checks sys.modules for previously imported modules. Built-in modules − Searches Python's standard library. sys.path − Searches directories in sys.path (current directory first). If not found anywhere, raises ModuleNotFoundError. Import Order Convention Import statements should be ...

Read More

Maximum count of characters that can replace ? by at most A 0s and B 1s with no adjacent duplicates

Thanweera Nourin A V
Thanweera Nourin A V
Updated on 15-Mar-2026 823 Views

In this problem, we need to replace '?' characters in a string with '0's and '1's such that no two adjacent characters are the same, while maximizing the number of replacements using at most A zeros and B ones. Syntax int maximumChar(char *str, int aCount, int bCount); Problem Statement Given a string containing '*' and '?' characters, and two integers A and B representing available 0s and 1s, find the maximum number of '?' characters that can be replaced without creating adjacent duplicates. Algorithm The approach involves the following steps − ...

Read More

Position of the leftmost set bit in a given binary string where all 1s appear at the end

Thanweera Nourin A V
Thanweera Nourin A V
Updated on 15-Mar-2026 443 Views

The aim of this article is to implement a program to find the position of the leftmost set bit in a given binary string where all 1s appear at the end. A binary string is a sequence of bits (0s and 1s) used to represent data in binary format. In this problem, we are given a binary string where all the 1s are grouped together at the rightmost positions, and we need to find the leftmost position where the first '1' appears. Syntax int findFirstBit(char* str, int length); Problem Statement Given a binary ...

Read More

largest string formed by choosing words from a given Sentence as per given Pattern

Ravi Ranjan
Ravi Ranjan
Updated on 15-Mar-2026 421 Views

To find the largest string formed by choosing words from a given sentence, a user should know about the lexicographically largest string. A lexicographically largest string is a string, when sorted alphabetically, it would appear at the last if we form all possible strings from the selected words. For example: {lion, zebra, apple} will be lexicographically sorted as {apple, lion, zebra}. In this article, we have been given a string and a pattern. Based on this pattern, we have to find the lexicographically largest string matching the given pattern by choosing words from the sentence using C. Here is ...

Read More

Find the count of Alphabetic and Alphanumeric strings from given Array of Strings

Thanweera Nourin A V
Thanweera Nourin A V
Updated on 15-Mar-2026 524 Views

In C programming, counting alphabetic and alphanumeric strings from an array involves checking each character in every string. An alphabetic string contains only letters (a-z, A-Z), while an alphanumeric string contains both letters and digits (0-9). Syntax int isAlphabetic(char str[]); int isAlphanumeric(char str[]); void countStrings(char arr[][MAX_LEN], int n); Algorithm The approach to solve this problem involves the following steps − Step 1 − Iterate through each string in the array Step 2 − Check each character to determine if string is alphabetic or alphanumeric Step 3 − Count occurrences and maintain frequency ...

Read More

Count of sum of “10” subsequences for each 1 in string with A 1s, B 10s and C 0s

Thanweera Nourin A V
Thanweera Nourin A V
Updated on 15-Mar-2026 300 Views

In C programming, we need to find the count of "10" subsequences for each '1' in a string that contains A individual 1s, B "10" substrings, and C individual 0s. This problem involves counting subsequences where each '1' can pair with available '0' characters. Syntax long long maximumSubSeq(int A, int B, int C); Problem Understanding Given three parameters − A − Number of standalone '1' characters B − Number of "10" substrings C − Number of standalone '0' characters We need to count all possible "10" subsequences from the concatenated string. ...

Read More

Convert a string Str1 to Str2 by moving B to right and A to left without crossover

Thanweera Nourin A V
Thanweera Nourin A V
Updated on 15-Mar-2026 313 Views

The aim of this article is to implement a program to convert a string Str1 to Str2 by moving B to right and A to left without crossover. In this problem, we have two strings where characters 'A' can only move left, characters 'B' can only move right, and empty spaces are represented by '#'. The key constraint is that 'A' and 'B' characters cannot cross over each other during movement. Syntax bool moveRobots(char str1[], char str2[]); Examples Example 1 Input: str1 = "#B#A#", str2 = "##BA#" Output: Yes ...

Read More

C Program To Write Your Own atoi()

Thanweera Nourin A V
Thanweera Nourin A V
Updated on 15-Mar-2026 896 Views

The atoi() function in C converts a string representation of a number into an integer value. The name stands for "ASCII to Integer". While the standard library provides atoi(), implementing your own version helps understand string parsing and character-to-number conversion. Syntax int myAtoi(const char *str); Parameters str − Pointer to the null-terminated string to be converted Return Value Returns the converted integer value. If no valid conversion can be performed, it returns 0. Example 1: Basic Implementation This example shows a simple implementation that handles positive numbers − ...

Read More

Producer-Consumer Problem in C

Way2Class
Way2Class
Updated on 15-Mar-2026 30K+ Views

The producer-consumer problem is a classic synchronization challenge in concurrent programming where multiple threads share a common buffer. Producers generate data and place it into the buffer, while consumers remove and process data from the buffer. The main challenge is coordinating these operations to prevent race conditions and ensure data integrity. Syntax /* Basic structure for producer-consumer implementation */ pthread_t producer_thread, consumer_thread; pthread_mutex_t mutex; pthread_cond_t condition_variable; void* producer(void* arg); void* consumer(void* arg); Problem Statement The producer-consumer problem involves two types of processes − Producer − Generates data and puts it into ...

Read More
Showing 9001–9010 of 21,090 articles
« Prev 1 899 900 901 902 903 2109 Next »
Advertisements