Sunday 19 August 2018

KERALA PEOPLE NEED YOUR HELP


The people of Kerala have been devastated by the continuous rains and the excessive floods that have affected the region. There have been continuous rains in majority of Kerala which lead to flooding and destruction of life and property.

Water Caused Destruction


People have been hurt both physically and mentally as they lost their houses, property, lives and families to the excess water that has lodged almost every district in the state. According to an official report, in the past 10 days, about 300 people have lost their lives with a destruction of property amounting to $3 billion.

The main purpose of this article is to request people to support people of Kerala by donating as little as 20-30 Rs. This money will help feed the needy and get them proper treatment and care.


  
Ways to donate :
  • The primary option to donate is, directly to the state by giving your money to the Kerala Chief Minister Disaster Relief Fund (CMDRF). It has been started by the government to request funds for the revival of the state.
  • The other option will be to send money directly using TEZ or any other UPI service. The government has setup a disaster relief fund with the UPI as keralacmdrf@sbi 
    • Go to your UPI payment App
    • Type in the payment address
    • Pour your heart out in the amount section
    • Pay for betterment of peoples' lives
  •  Paying via Ketto. Ketto is a fund-raiser organization, where people can ask for croud funding for their causes and ideas. There is a fund-raiser going on for the Kerala Floods, just visit the link and donate whatever amount you feel like (The minimum donation amount is 300Rs)
  • Finally if you do not seem to be able to spare even 50Rs, just visit those little Advertisements on this page, anything that this post generates will be sent to the Disaster Relief Fund.

May God Protect The People And Help Them Overcome This Calamity 

Friday 10 August 2018

Sum Of Array Elements Using Recursion

QUESTION DESCRIPTION :

Given an array of integer elements, find sum of array elements using recursion.

TEST CASE 1

INPUT

5
1 2 3 4 5

OUTPUT

15


TEST CASE 2

INPUT

4
4 4 4 4

OUTPUT

16



EXPLANATION :

The question requires you to input a set of numbers and then find their sum using the recursive addition.
The number of integers is given in the first line say "n", then n space seperated integers follow.

ALGORITHM :

For this code, we will input the "n" value, which gives the numbers of integers to be added. Then initialize the array to n. Then input the n values in the array using a loop. Then instead of using a loop to traverse through the array we will simulate it using recursion.

Steps:

  1. Input the number of integers that have to be added (The value of n)
  2. Initialize an array to size n (arr)
  3. Loop till n and input all n integers into the array
  4. Call the add() function and pass the array and n to it.
    (Set the return type of function to be int)

    Inside the add() function:
    1. If there are more values available, i.e. n>0, return the current arr[n] value and call the add function again with n-1 as the argument.
      (This is the recursive base case)
    2. Otherwise return 0
      (This is the exit case)
  5. Print the result of the add() function (don't need to save the result)
  6. Exit
P.S. It is a bit difficult to explain recursive algorithms and recursive statements. It is recommended to read the code and try to understand. Ask doubts in the comments.

P.P.S. :Here are a few links to basic recursion tutorials
SOLUTION : (Please use this as reference only)

Link to Code : Sum Of Array Elements Using Recursion

(Please Try To Refrain From Copying The Code)

Wednesday 8 August 2018

Pool

QUESTION DESCRIPTION :

You are planning to go for swimming classes. You would prefer to enroll in the centre which has the swimming pool of a greater area. In the first center that you visit, the swimming pool is circular shape (radius- r). In the next center you visit, the swimming pool is of square shape (size-S). Write a program that will help you to make the choice of the swimming pool.

Input Format: Input consists of 2 integers. The first one corresponds to the Radius of the circle, and the second one is the Side of the square

TEST CASE 1

INPUT
 
20
5

OUTPUT

I prefer centre 1


TEST CASE 2

INPUT

5
20

OUTPUT

I prefer centre 2


EXPLANATION :

The question requires you to input the radius of a circle, side of a square and then compare their areas, the one with the bigger area is the choice of the person. 

ALGORITHM :

Although this code is very easy we can add a space optimization by directly using the result of the calculation.

Steps:
  1. Input the Radius(R) and Side(S) of the circle and square respectively.
  2. Calculate the area of Circle (π*r*r) > Area1
  3. Calculate the area of the square (s*s) > Area2
  4. Compare the areas:
    1. If Area1< Area2 print "I prefer centre 2"
    2. If Area1> Area2 print "I prefer centre 1"
  5. Exit
P.S. Optimizations such as using less variables are mostly not relevant in the 21st Century scenario as the RAM add HDD sizes are large but such optimizations are recommended wherever possible in order to become a better programmer.

SOLUTION : (Please use this as reference only)



Link to Code : Pool

(Please Try To Refrain From Copying The Code)