First, solve the problem on your own or just dry run it.

here is the leetcode problem

//this takes the O(n log n ) time complexity

// spsce complexity is O(1) which is constant space.

#include <iostream>

#include<bits/stdc++.h>

using namespace std;

int twonumberSum(int array[],int targetSum,int n)

{

sort(array, array +…

visualization with Pandas, Matplotlib and Seaborn

Line Plot:

In Matplotlib we can create a line chart by calling the plot method. We can also plot multiple columns in one graph, by looping through the columns we want and plotting each column on the same axis.

import matplotlib.pyplot as plt

x =…

hey, guys now we are gonna look at what is tail recursion and non-tail recursion. what is the difference between them and which is best to use?

Recursion:

Recursion is the calling the function itself is called recursion.we all are familiar with this normal recursion.

write a recursive function to print…

Now we are looking at what are the different cloud services available and what are the differences between them?

Cloud Service Providers (CSPs) offer high-quality services with multiple capabilities, excellent availability, good performance, high security, and customer support. …

Now we are going to look at the different ways to find no of digits in a number

  1. Iterative solution
  2. Recursive solution
  3. logarithmic solution

Iterative solution

int count_digits(long n){
while(n!=0)
{
n=n/10;
count++;
}
return count;
}

2.Recursive Solution

int count_digits(long n)
{
if(n==0):
return 0;
else
return 1+ count_digits(n/10);}

3. Logarithmic solution

int count_digits(long n)
{
return floor(log_₁₀n +1);
}#here we use that log_₁₀n it's value is 2.08 so,we use floor to terminate the decimal points and add one to the value so we get the result

The iterative and recursive solutions are common and but the logarithmic solution is the fastest of all these.

I hope it helps you!

Happy Reading!!!!!!!!!!!!!!!!!

Prasad Bylapudi

Tech enthusiast |Python programmer|loves competitive programming|

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