Tag Archives: Cpp - Page 3

Largest Two Elements – Single Loop

Problem Given an array of positive integers. Find the first and second largest elements in the array. You are not allowed to use more than one loop in your solution. Solution The solution is to use a single loop to …

Read more »

Find the two largest numbers in an array

Find two largest elements array Given an array of positive integers. Find the first and second largest elements in the array. Largest two numbers in an array solution One solution is to use two loops. The first loop finds the …

Read more »

Integer division c++

Integer division problem definition Given the following function which computes integer division. Debug the code and identify the major bugs. Modify the code to fix those bugs. Assume all integer variables are within range and no overflow is about to …

Read more »

Sum of Integers in a Range

Problem Write a function to compute the sum of integers between two given integer values. Solution The naive solution is to loop by going from the lower integer ending at the higher integer while calculating the sum. The other solution …

Read more »

Non repeating character string

Find non repeating character string Develop an algorithm to print the first none repeating character in a string for example the first none repeating character in the string “baby” is “a” Algorithm A brute force method requires us to use …

Read more »

Bitwise operators in c++

Problem Write a C++ function that takes a character as input and returns true if the second significant bit of the binary representation of the character is set (i.e equals to 1) otherwise return false. Solution This is a bitwise …

Read more »

Nested loop running time

Running time of nested loop Given the following pattern matching algorithm which decides whether there is an occurrence of a pattern of size (m) in a text of size (n). The algorithm compares the pattern in a given location in …

Read more »

Page 3 of 612345...Last »