Solve Me First

Introduction

For most Developers , it’s easy to be satisfied with code that just works. This however may be a temporal comfort , because while many of us may think there is demand for developers the truth could not be further from it . In this world of a silicon existence there is only demand for great developers. It is therefor to this end that I share my knowledge and experience in the world of Data Structures and Algorithms in the hopes to both teach and learn from others.
My first case is a Hackerrank challenge called Solve Me first. This is the easiest and very first problem in the Hackerrank problem solving section. The solution to this problem and my complete series will be written in the python 3 programming language.

Problem Statement.

I will go ahead and display the problem statement as it is on the Hackerrank website so as to clearly give a picture of the solution goal and problem constraints.
Complete the function solveMeFirst to compute the sum of two integers.

Example

Return

a = 7
b = 3
return 10

Function Description

Complete the solveMeFirst function in the editor below.

solveMeFirst has the following parameters:

  • int a: the first value
  • int b: the second value

Returns
int: the sum of a and b

Constraints

1 ≤ a,b ≤ 1000

Sample Input

a = 2
b = 3

Sample Output

5

Explanation

2 + 3 = 5

Solution

def solveMeFirst(a,b):# Hint: Type return a+b belowreturn a+b"""
collect the first number from the standard input and convert it to an integer. Just to be sure you can make conduct mathematical operations on the inputs.
NOTE:
If inputs are strings the (+) operator will carry a different meaning and concatenate the strings instead of adding the numbers.
E.g
'2' + '3' = '23'
which is not what we want.
"""
num1 = int(input())
num2 = int(input())"""
call the solvemeFirst function with the input values stored in the variables num1 and num2 which stores the values retrieved from the standard input.
"""res = solveMeFirst(num1,num2)## print out the output as is the requirement for the completion of the challenge.print(res)"""
time complexity = O(1)
space complexity = O(1)
"""

conclusion

I know to the programming veterans this goes without saying , but if you are a beginner this is the first and important lesson that helps you get comfortable with working with standard input in python, typecasting and working with functions and their arguments.
Remember becoming a master at anything means mastering the basics.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Munalula Sikazwe

Munalula Sikazwe

13 Followers

I’m a computer Scientist and Python Developer . My hobbies are playing chess and watching movies with convoluted storylines like Tenet or Inception.