Skip to main content

Featured

Solve LeetCode 30 Substring with Concatenation of All Words in C++ using sliding window and frequency maps

Substring with Concatenation of All Words in C++ LeetCode 30 · sliding window · frequency maps · string_view 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 30. Substring with Concatenation of All Words Given a string s and an array of strings words , where every word has the same length, find all starting indices of substrings that are a concatenation of every word exactly once, in any order. Approach This solution uses a sliding window and two frequency maps. Since every word has the same length, the string is checked in chunks of len characters. freq stores the required frequency of each word. temp stores the frequencies in the current window. count tracks the number of word-sized chunks in the window. If a word occurs too ...

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

πŸ”€ C Program to Print Repeated Alphabet Increasing and Decreasing Pattern

πŸ“„ Source Code:
#include<stdio.h>

int main( )
{
    int num;

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

    for(int i=num;i>=1;i--)
    {
        for(int j=1;j<=i;j++)
        {
            printf("%c ",i+64);
        }

        printf("\n");
    }

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

        printf("\n");
    }
}
  
πŸ’» Expected Output (Input: 5):
Enter the number:
5
E E E E E
D D D D
C C C
B B
A
A
B B
C C C
D D D D
E E E E E
  
```

πŸ”€ C Program to Print Alphabet Increasing and Decreasing Pattern

πŸ“„ Source Code:
#include<stdio.h>

int main( )
{
    int num;

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

    for(int i=num;i>=1;i--)
    {
        for(int j=1;j<=i;j++)
        {
            printf("%c ",j+64);
        }

        printf("\n");
    }

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

        printf("\n");
    }
}
  
πŸ’» Expected Output (Input: 5):
Enter the number:
5
A B C D E
A B C D
A B C
A B
A
A
A B
A B C
A B C D
A B C D E
  
```

πŸ”’ C Program to Print Repeated Binary Increasing and Decreasing Pattern

πŸ“„ Source Code:
#include<stdio.h>

int main( )
{
    int num;

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

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

        printf("\n");
    }

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

        printf("\n");
    }
}
  
πŸ’» Expected Output (Input: 5):
Enter the number:
5
1 1 1 1 1
0 0 0 0
1 1 1
0 0
1
1
0 0
1 1 1
0 0 0 0
1 1 1 1 1
  
```

πŸ”’ C Program to Print Binary Increasing and Decreasing Pattern

πŸ“„ Source Code:
#include<stdio.h>

int main( )
{
    int num;

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

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

        printf("\n");
    }

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

        printf("\n");
    }
}
  
πŸ’» Expected Output (Input: 5):
Enter the number:
5
1 0 1 0 1
1 0 1 0
1 0 1
1 0
1
1
1 0
1 0 1
1 0 1 0
1 0 1 0 1
  
```

πŸ”’ C Program to Print Repeated Number Increasing and Decreasing Pattern

πŸ“„ Source Code:
#include<stdio.h>

int main( )
{
    int num;

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

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

        printf("\n");
    }

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

        printf("\n");
    }
}
  
πŸ’» Expected Output (Input: 5):
Enter the number:
5
5 5 5 5 5
4 4 4 4
3 3 3
2 2
1
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
  
```

πŸ”’ C Program to Print Increasing and Decreasing Number Pattern

πŸ“„ Source Code:
#include<stdio.h>

int main( )
{
    int num;

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

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

        printf("\n");
    }

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

        printf("\n");
    }
}
  
πŸ’» Expected Output (Input: 5):
Enter the number:
5
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
  

πŸ”’ C Program to Print Continuous Number Increasing and Decreasing Pattern

πŸ“„ Source Code:
#include<stdio.h>

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

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

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

        printf("\n");
    }

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

        printf("\n");
    }
}
  
πŸ’» Expected Output (Input: 5):
Enter the number:
5
0 1 2 3 4
5 6 7 8
9 10 11
12 13
14
15
16 17
18 19 20
21 22 23 24
25 26 27 28 29
  

Comments

Popular Posts

πŸŒ™