DATA TYPES
Data type specifies the type of data that the variable can store like integer,
character, floating, double, etc.
OPERATORS
0
a
ERROR
d
2
c
1
b
a += a * b / 2 % 4 - b++ * b + --a;
What will be the value of a?
If , a = 2 and b = 1
IF ELSE AND SWITCH
Arrays
An array is a collection of items of same data type stored at contiguous memory
locations.
Strings
A string is a sequence of characters and can contain letters, numbers,
symbols and even spaces.
For loop
A for loop is a control structure in programming that allows you to execute a specific
block of code repeatedly. It’s especially useful when you want to perform the same task
multiple times without duplicating your code
Components of a for loop:
While loop
A while loop is a control structure
in programming that repeatedly
executes a block of code as long as
a specified condition remains true.
Do while loop
A do...while loop is similar to a while
loop, except the fact that it is
guaranteed to execute at least one
time.
An integer is considered a palindrome when it reads the same backward as forward.
Palindrome
Example 1:
Input: N = 123
Output: Not Palindrome
Example 2:
Input: N = 121
Output: Palindrome
Approach: We can reverse the original number and compare the original with the
reversed number. If both are the same, the number qualifies as a palindrome number.
Let’s understand the procedure to reverse a number.
At every step extract the last digit using the % operator. Suppose X%10 = d.
We will append this last digit, d to Y using a formula 10*Y+d.
The last digit of X has been used. Discard it using X/10.
Example 1:
Input: num1 = 4, num2 = 8
Output: 4
GCD/HCF
Example 2:
Input: num1 = 3, num2 = 6
Output: 3
Algorithm / Intuition:
Intuition: Simply traverse from 1 to min(a,b) and check for every number.
Approach:
Traverse from 1 to min(a,b).
And check if i is divisible by both a and b.If yes store it in the answer.
Find the maximum value of i which divides both a and b.
Pattern 1 - Right-Angled Triangle Pattern
Problem Statement: Given an integer N, print the following pattern :
Patterns 2 - Star Pyramid
Problem Statement: Given an integer N, print the following pattern :
FUNCTIONS
A function is a set of statements that when called perform some specific task. It is
the basic building block of a programming language that provides modularity and
code reusability.
TIME COMPLEXITY
Time Complexity: The time complexity of an algorithm quantifies the amount
of time taken by an algorithm to run as a function of the length of the input.
SPACE COMPLEXITY
The space Complexity of an algorithm is the total space taken by the algorithm
with respect to the input size. Space complexity includes both Auxiliary space
and space used by input.
Auxiliary Space is the extra space or temporary space used by an algorithm.
Example:
The variables a and b are used to store the inputs
but c refers to the space we are using to solve the
problem and c is the auxiliary space. Here the space
complexity will be O(3).
Similarly, if we use an array of size n, the space
complexity will be O(N).