Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 186 of 377

c32rtomb() function in C/C++?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 197 Views

In C programming, the c32rtomb() function is used to convert a 32-bit wide character (char32_t) to its corresponding multibyte character representation. This function is defined in the uchar.h header file and is part of the C11 standard for Unicode support. Syntax size_t c32rtomb(char *s, char32_t c32, mbstate_t *ps); Parameters s − Pointer to a character array where the multibyte character will be stored c32 − The 32-bit wide character to convert ps − Pointer to an mbstate_t object that holds the conversion state Return Value The function returns the number ...

Read More

A data structure for n elements and O(1) operations?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 621 Views

Here we will see one data structure with n elements, and O(1) operations. So the operations will take constant amount of time to execute. The data structure will hold n elements (from 0 to n-1). The data can be in any order. The insertion, deletion and searching will take O(1) amount of time. To solve this problem, we will use one Boolean array. This will indicate that the item is present or not at position i. If the item is present, it will hold 1, otherwise 0. Syntax void init(bool dataStructure[], int n); ...

Read More

A C Programming Language Puzzle?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 548 Views

Here we will see one C programming language puzzle question. Suppose we have two numbers 48 and 96. We have to add the first number after the second one. So final result will be like 9648. But we cannot use any logical, arithmetic, string related operations, also cannot use any pre-defined functions. So how can we do that? This is easy. We can do by using Token Pasting operator(##) in C. The Token Pasting operator is a preprocessor operator. It sends commands to compiler to add or concatenate two tokens into one string. We use this operator at the ...

Read More

2's compliment for a given string using XOR ?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 1K+ Views

In C programming, finding the 2's complement of a binary string can be efficiently done using the XOR operation. The 2's complement is calculated as 1's complement + 1. We use XOR to flip bits and implement a specific algorithm that traverses from the least significant bit (LSB). Syntax char* get2sComplement(char* binaryString); Algorithm The algorithm works by traversing the binary string from right to left − Ignore all trailing zeros until we find the first '1' Keep the first '1' unchanged Flip all remaining bits using XOR operation If no '1' is ...

Read More

1 to n bit numbers with no consecutive 1s in binary representation?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 555 Views

In this problem, we need to count binary numbers of n bits that contain no consecutive 1s in their binary representation. For example, in 3-bit binary strings, numbers like 011, 110, and 111 have consecutive 1s, while 5 numbers (000, 001, 010, 100, 101) do not have consecutive 1s. The solution uses dynamic programming with two arrays: one tracking numbers ending with 0 and another tracking numbers ending with 1. Syntax int countBinaryNumbers(int n); Algorithm The recurrence relations are − endWithZero[i] = endWithZero[i-1] + endWithOne[i-1] (we can append 0 to any ...

Read More

attribute((constructor)) and attribute((destructor)) syntaxes in C in tutorials point ?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 3K+ Views

Here we will see how to write a code where two functions are present, and one function will be executed before the main function, and another function will be executed after main function. These features are used to do some startup task before executing main, and some clean up task after executing main. To do this task we have to put attribute for these two functions. When the attribute is constructor attribute, then it will be executed before main(), and when the attribute is destructor type, then it will be executed after main(). We are using GCC functions. ...

Read More

Length of Longest Fibonacci Subsequence in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 221 Views

Suppose we have a sequence X_1, X_2, ..., X_n is fibonacci-like if −n >= 3X_i + X_{i+1} = X_{i+2} for all i + 2 = 3 otherwise return 0.Let us see the following implementation to get better understanding −Example#include using namespace std; class Solution {    public:    int lenLongestFibSubseq(vector & A) {       int ret = 0;       unordered_map m;       int n = A.size();       vector < vector > dp(n, vector (n));       for(int i = 0; i < n; i++){         ...

Read More

Spiral Matrix III in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 473 Views

Suppose we have a 2 dimensional grid with R rows and C columns, we start from (r0, c0) facing east. Here, the north-west corner of the grid is at the first row and column, and the south-east corner of the grid is at the last row and column. We will walk in a clockwise spiral shape to visit every position in this grid. When we are at the outside the boundary of the grid, we continue our walk outside the grid (but may return to the grid boundary later.). We have to find a list of coordinates representing the positions ...

Read More

Partition Array into Disjoint Intervals in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 501 Views

Suppose we have an array A, we have to partition it into two subarrays left and right such that −Every element in left subarray is less than or equal to every element in right subarray.left and right subarrays are non-empty.left subarray has the smallest possible size.We have to find the length of left after such a partitioning. It is guaranteed that such a partitioning exists.So if the input is like [5, 0, 3, 8, 6], then the output will be 3, as left array will be [5, 0, 3] and right subarray will be [8, 6].To solve this, we will ...

Read More

Interval List Intersections in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 380 Views

Suppose we have two lists of closed intervals, here each list of intervals is pairwise disjoint and in sorted order. We have ti find the intersection of these two interval lists.We know that the closed interval [a, b] is denoted as a A[i][1] or A[i][1] B[j][1] or B[j][1] B[j][1]:          j+=1       else:          i+=1    return result    def intersect(self,a,b):       if a[0]=b[0]:          return True       if b[0]=a[0]:          return True       return False ob = Solution() print(ob.intervalIntersection([[0,2],[5,10],[13,23],[24,25]],[[1,5],[8,12],[15,24],[25,27]]))Input[[0,2],[5,10],[13,23],[24,25]] [[1,5],[8,12],[15,24],[25,27]]Output[[1, 2], [5, 5], [8, 10], [15, 23], [24, 24], [25, 25]]

Read More
Showing 1851–1860 of 3,768 articles
« Prev 1 184 185 186 187 188 377 Next »
Advertisements