Skip to main content

Featured

Solve LeetCode 3 Longest Substring Without Repeating Characters in C++ using the sliding window

Longest Substring Without Repeating Characters in C++ LeetCode 3 · sliding window · last index array Table of Contents Problem Statement Approach Algorithm C++ Program Input Sample Output Output Explanation Dry Run Flow of Execution Time Complexity Space Complexity Applications Key Points Interview Questions Frequently Asked Questions Conclusion Problem Statement 3. Longest Substring Without Repeating Characters Given a string s , find the length of the longest substring that contains no repeating characters. A substring is a continuous part of the string, so "pwke" is a subsequence of "pwwkew" but not a substring. Approach We use a sliding window . The window is the part of the string between start and end , and we always keep it free of repeated characters. An array lastIndex of size 128 remembers the most recent position of every ASCII ...

C Triangle Pattern Programs 4: Star, Number, Alphabet & Binary Patterns with Output

Pattern Name

Left-Aligned Right-Angled Triangle Star Pattern 

Other acceptable names:

  • Increasing Star Triangle Pattern

  • Left-Aligned Triangle Pattern

  • Right-Angled Star Triangle

  • Half Pyramid Pattern using Stars

This is one of the most classic patterns for beginners in C programming









๐Ÿ”ท Left-Aligned Continuous Number Triangle Pattern

#include <stdio.h>

int main( )
{
    int num, k = 0;

    printf("Enter the number:\n");
    scanf("%d", &num);

    for(int i = 1; i <= num; i++)
    {
        for(int j = 1; j <= i; j++)
        {
            printf("%d ", k++);
        }

        printf("\n");
    }

    return 0;
}










๐Ÿ”ท Triangle Binary Number Pattern

#include <stdio.h>

int main( )
{
    int num, k = 0;

    printf("Enter the number:\n");
    scanf("%d", &num);

    for(int i = 1; i <= num; i++)
    {
        for(int j = 1; j <= i; j++)
        {
            printf("%d ", j % 2);
        }

        printf("\n");
    }

    return 0;
}



*********************************************** 
 

*

* *

* * *

* * * *

* * * * *

#include<stdio.h>

int main( )

{

int num,i,j;

printf("Enter the number:\n");

scanf("%d",&num);

for(i=1;i<=num;i++)

{

        for(j=1;j<=i;j++)

        {

                printf("* ");

        }

        printf("\n");

}

}

***********************************************  

1

2 2

3 3 3

4 4 4 4

5 5 5 5 5

#include<stdio.h>

int main( )

{

int num,i,j;

printf("Enter the number:\n");

scanf("%d",&num);

for(i=1;i<=num;i++)

{

        for(j=1;j<=i;j++)

        {

                printf("%d ",i);

        }

        printf("\n");

}

}

***********************************************  

1

1 2

1 2 3

1 2 3 4

1 2 3 4 5

#include<stdio.h>

int main( )

{

int num,i,j;

printf("Enter the number:\n");

scanf("%d",&num);

for(i=1;i<=num;i++)

{

        for(j=1;j<=i;j++)

        {

                printf("%d ",j);

        }

        printf("\n");

}

}

***********************************************  

A

B B

C C C

D D D D

E E E E E

#include<stdio.h>

int main( )

{

int num,i,j;

printf("Enter the number:\n");

scanf("%d",&num);

for(i=1;i<=num;i++)

{

        for(j=1;j<=i;j++)

        {

                printf("%c ",i+64);

        }

        printf("\n");

}

}
***********************************************  

A

A B

A B C

A B C D

A B C D E


#include<stdio.h>

int main( )

{

int num,i,j;

printf("Enter the number:\n");

scanf("%d",&num);

for(i=1;i<=num;i++)

{

        for(j=1;j<=i;j++)

        {

                printf("%c ",j+64);

        }

        printf("\n");

}

}

***********************************************  

5
4 4
3 3 3
2 2 2 2
1 1 1 1 1
#include<stdio.h>
int main( )
{
int num,i,j;
printf("Enter the number:\n");
scanf("%d",&num);
for(i=num;i>=1;i--)
{
        for(j=num;j>=i;j--)
        {
                printf("%d ",i);
        }
        printf("\n");

}
}




Comments

Popular Posts

๐ŸŒ™