Sudhir sharma has Published 1149 Articles

XOR counts of 0s and 1s in binary representation in C++

sudhir sharma

sudhir sharma

Updated on 17-Apr-2020 15:37:35

225 Views

In this problem, we are given a number. Our task is to find the XOR of the count of 0s and 1s in the binary representation of the number.Let’s take an example to understand the problem, Inputn = 9Output0Explanationbinary = 1001 Count of 0s = 2 Count of 1s = ... Read More

Write your own strcmp that ignores cases in C++

sudhir sharma

sudhir sharma

Updated on 17-Apr-2020 14:31:26

784 Views

Here, we have to create a strcmp (string compare) function that compares two string but ignores cases of the characters of the string. The function will return -1 if string1 < string2, 0 if string1 = string2, 1 if string1 > string2.Let’s take an example to understand the problem, Inputstring1 ... Read More

Write an iterative O(Log y) function for pow(x, y) in C++

sudhir sharma

sudhir sharma

Updated on 17-Apr-2020 13:57:56

545 Views

In this problem, we are given two integers x and y. Our task is to create a function that will be equivalent to pow(x, y) using an iterative approach that will complete the task in time complexity of 0(Log y).Let’s take a few examples to understand the problem, Inputx = ... Read More

Write an Efficient C Program to Reverse Bits of a Number in C++

sudhir sharma

sudhir sharma

Updated on 17-Apr-2020 13:29:53

1K+ Views

In this problem, we are given an unsigned integer n. Our task is to create a program that returns the number which is generated by reversing all the bits of the number.Let’s take an example to understand the problem, Inputn = 1Output2147483648Explanationbinary of 1 is 000...0001, the reverse is 100...0000.To ... Read More

Write Code to Determine if Two Trees are Identical in C++

sudhir sharma

sudhir sharma

Updated on 17-Apr-2020 13:17:27

379 Views

In this problem, we are given two trees. Our task is to write a code to check whether the two trees are identical or not.Two trees are said to be identical if elements of the arrays have the same value and orientation.ExampleAs both of the trees have the same values ... Read More

Writing C/C++ code efficiently in Competitive programming

sudhir sharma

sudhir sharma

Updated on 17-Apr-2020 13:17:18

422 Views

In competitive programming, the most important thing is an effective code. Optimized and faster code is important and can make a difference in the ranks of the programmer.To write an effective c/c++ code in competitive programming, here are some effective tools for writing c/c++ code efficiently, First, let’s recall some ... Read More

Write your own memcpy() and memmove() in C++

sudhir sharma

sudhir sharma

Updated on 17-Apr-2020 13:07:34

995 Views

memcpy() function is an inbuilt function that is used to copy data from source location to destination location.Prototype of memcpy function −void * memcpy(void *destination_location, void *source_location, size_t size)We will character by character copy data from source to destination.Program to show the implementation of the solution, Example Live Demo#include #include void ... Read More

Writing OS Independent Code in C/C++

sudhir sharma

sudhir sharma

Updated on 17-Apr-2020 12:42:29

410 Views

A program that can interact with the operating system irrespective of the OS on which it runs.Most of the compilers of c/c++ have the power to define macros that detect OS.Some Macros of GCC compiler are −_WIN32: macros for 32 bit and 64-bit Windows OS._WIN64: macros for 64-bit Windows OS._UNIX: ... Read More

XOR of a submatrix queries in C++

sudhir sharma

sudhir sharma

Updated on 17-Apr-2020 12:41:02

165 Views

In this problem, we are given a N x N matrix and some queries, each query contains the top-left and bottom-right corner of the submatrix created from this matrix. Our task is to find the XOR of all elements of the submatrix defined by the querries.Let’s take an example to ... Read More

Written version of Logical operators in C++

sudhir sharma

sudhir sharma

Updated on 17-Apr-2020 12:38:22

184 Views

In c++ programming language, there are keywords that can be used in place of logical operators. The keywords are initially used in c when the keyboards didn’t support symbols like &&, !, ||, etc. Now, here are some written version of logical operators in c++.Operators and their written versions are ... Read More

Advertisements