title-img


Flipping bits

You will be given a list of 32 bit unsigned integers. Flip all the bits ( 1 -> 0 and 0 -> 1 ) and return the result as an unsigned integer. Function Description Complete the flippingBits function in the editor below. flippingBits has the following parameter(s): int n: an integer Returns int: the unsigned decimal integer result Input Format The first line of the input contains q, the number of queries. Each of the next q lines contain an integer, n, to process. Constrai

View Solution →

Time Complexity: Primality

A prime is a natural number greater than 1 that has no positive divisors other than 1 and itself. Given p integers, determine the primality of each integer and return Prime or Not prime on a new line. Note: If possible, try to come up with an primality algorithm, or see what sort of optimizations you can come up with for an O(n) algorithm. Be sure to check out the Editorial after submitting your code. Function Description Complete the primality function in the editor below. prima

View Solution →

Friend Circle Queries

The population of HackerWorld is 10 ^ 9. Initially, none of the people are friends with each other. In order to start a friendship, two persons a and b have to shake hands, where 1 <= a, b <= 10^9. The friendship relation is transitive, that is if a and b shake hands with each other, a and friends of a become friends with b and friends of b. You will be given q queries. After each query, you need to report the size of the largest friend circle (the largest group of friends) formed after co

View Solution →

Maximum Xor

You are given an array arr of n elements. A list of integers, queries is given as an input, find the maximum value of queries[ j ] each arr[ i ] for all 0 <= i < n, where represents xor of two elements. Note that there are multiple test cases in one input file. Function Description Complete the maxXor function in the editor below. It must return an array of integers, each representing the maximum xor value for each element queries[ j ] against all elements of arr. maxXor has t

View Solution →

Sales by Match

There is a large pile of socks that must be paired by color. Given an array of integers representing the color of each sock, determine how many pairs of socks with matching colors there are. Function Description Complete the sockMerchant function in the editor below. sockMerchant has the following parameter(s): int n: the number of socks in the pile int ar[n]: the colors of each sock Returns int: the number of pairs Input Format The first line contains an integer n, the

View Solution →