DEV Community

Cover image for Solve Me First - Problem Solving | HackerRank
Deepak Raj
Deepak Raj

Posted on • Originally published at codeperfectplus.com on

1

Solve Me First - Problem Solving | HackerRank

Solve me first is easy-level Python problem that requires basic knowledge of Python. In this post, we will provide a Python solution for Solve me first.

Problem Statement and Explanation

Add two numbers and return the sum. The numbers are provided as input to the function.

Input Format

  • int a - first number
  • int b - second number

Output Format

  • int - sum of the two numbers

Solve Me First Solution in Python

def solveMeFirst(a:int,b:int):
# Hint: Type return a+b below
return a + b
num1 = int(input())
num2 = int(input())
res = solveMeFirst(num1,num2)
print(res)

Solve Me First Solution in C++

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int solveMeFirst(int a, int b) {
// Hint: Type return a+b; below:
return a + b;
}
int main() {
int num1, num2;
int sum;
cin>>num1>>num2;
sum = solveMeFirst(num1,num2);
cout<<sum;
return 0;
}

Explanation of Solution

  • The #include statements at the top of the code tell the compiler to include the necessary header files. These header files contain definitions for functions and variables that are used in the code.
  • The using namespace std statement tells the compiler to use the std namespace. This namespace contains many commonly used functions and variables, such as cin and cout.
  • The solveMeFirst function takes two integers as input and returns their sum. The function definition starts with the keyword int, which tells the compiler that the function returns an integer value. The function name is solveMeFirst, and it takes two arguments, a and b. The body of the function is enclosed in curly braces ({}). The first line of the function body returns the sum of a and b.
  • The main function is the entry point of the program. It prompts the user to enter two integers, calls the solveMeFirst function to calculate their sum, and then prints the sum to the console. The main function definition starts with the keyword int, which tells the compiler that the function returns an integer value. The function name is *main, and it takes no arguments. The body of the function is enclosed in curly braces ({}). The first line of the function body reads two integers from the user. The second line calls the solveMeFirst function to calculate the sum of the two integers. The third line prints the sum to the console.

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more