Skip to content

ashikbhuyan17/FoundationsOfCode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

FoundationsOfCode

Foundations Of Code

01. Add Two Numbers

Input: num1 = 5, num2 = 10
Output: 15
Explanation: 342 + 465 = 807

Complexity Analysis
    Time Complexity: O(1)
    Auxiliary Space: O(1)
Solution
let num1 = 5;
let num2 = 10;

let sum = num1 + num2;
console.log(sum); // Output: 15
let num1: number = 5;
let num2: number = 10;

let sum: number = num1 + num2;
console.log(sum); // Output: 15

02. Swap two Numbers

Input: num1 = 5, num2 = 10
Output: num1 = 10, num2 = 5

Complexity Analysis
    Time Complexity: O(1)
    Auxiliary Space: O(1)
Solution
let firstVariable = 10;
let secondVariable = 20
let temp;
temp = firstVariable
firstVariable = secondVariable
secondVariable = temp
console.log("🚀 ~ file: After swapping", firstVariable, secondVariable)

// Swapping without using a third variable
let firstVariable = 10;
let secondVariable = 20
firstVariable = firstVariable + secondVariable
secondVariable = firstVariable-secondVariable
firstVariable =firstVariable-secondVariable
console.log("🚀 ~ file: After swapping", firstVariable, secondVariable)

⬆ Back to Top

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published