Question Set 3

This is question set 3. Another day another set.Happy Coding!

"Talk is Cheap Just code it"


Problem 1-Kadane's Algorithm(Easy)

Given an integer array , find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.

   SAMPLE INPUT
 
    -2 1 -3 4 -1 2 1 -5 4
 SAMPLE OUTPUT
 
 6 [4+(-1)+2+1]
Link to the question-https://leetcode.com/problems/maximum-subarray/
Problem 2-GCD(Easy)
GCD (Greatest Common Divisor) or HCF (Highest Common Factor) of two numbers is the largest number that divides both of them.Find the GCD of two numbers.
PS-Try to learn Euclid method of calculating GCD
  SAMPLE INPUT
 
     a=96 b=56
SAMPLE OUTPUT
 
14
Link to the question-https://www.geeksforgeeks.org/c-program-find-gcd-hcf-two-numbers/
  
Problem 3-GCD of Array(Easy)
Given an array of numbers, find GCD of the array elements.
SAMPLE INPUT
 
       2 4 6 8
   SAMPLE OUTPUT
 
  2
 Link to the question-https://www.geeksforgeeks.org/gcd-two-array-numbers/

  Problem 4-Kadane's Algorithm Modified (Medium)

 Given n numbers (both +ve and -ve), arranged in a circle, fnd the maximum sum of       consecutive number.
       SAMPLE INPUT
 
       8 -8 9 -9 10 -11 12
   SAMPLE OUTPUT
 
  22 (12 + 8 - 8 + 9 - 9 + 10)
Link to the question-https://www.geeksforgeeks.org/maximum-contiguous-circular-sum/




       

Comments

Popular posts from this blog

Question Set 4

Question Set 5

Question Set 2