Skip to content
Related Articles

Related Articles

Improve Article

Webkul Interview Coding Round Pattern

  • Difficulty Level : Hard
  • Last Updated : 10 Dec, 2020

This is a mixed pattern which uses the different types in one and this pattern was asked to me when I was giving the 1st round of coding in Webkul Interview.

Examples: 

Input : 3
Output : 
                            @
                           @@@
                          @@@@@
                          *   *
                         **@@@**
                          *   *

Input : 5
Output : 
                            @
                           @@@
                          @@@@@
                         @@@@@@@
                         *     *
                        **     **
                       ***@@@@@***
                        **     **
                         *     *

Below is the implementation of the above pattern: 

C++




// C++ implementation
#include <bits/stdc++.h>
  
using namespace std;
 
// Driver code
int main() {
    int n, i, j;
    cin >> n ;
     
    for (i = 0; i < (n/2) + 2; i++){
        for (j = 0; j < n - i; j++){
            cout << " ";
        }
        for (j = 0; j < 2 * i + 1; j++){
            cout <<"@";
        }
        cout << "\n";
    }
     
    for (i = 0; i < n; i++){
        for (j = 0; j < (n/2) + 1; j++){
            if (j >= n / 2 - i && j >= i - n / 2){
                cout << "*" ;
            }
            else
            cout << " ";
        }
        for (j = 0; j < n; j++){
            if (i == n / 2)
                cout <<"@" ;
            else
                cout <<" ";
        }
        for (j = 0; j < (n / 2) + 1; j++){
            if (j >= n / 2 - i && j >= i - n / 2)
                cout <<"*";
        }
        cout <<"\n";
    }
    return 0;
}
 
// This code is contributed by shivanisinghss2110

C




// C implementation
#include <stdio.h>
 
// Driver code
int main() {
    int n, i, j;
    scanf("%d", &n);
     
    for (i = 0; i < (n/2) + 2; i++){
        for (j = 0; j < n - i; j++){
            printf(" ");
        }
        for (j = 0; j < 2 * i + 1; j++){
            printf("@");
        }
        printf("\n");
    }
     
    for (i = 0; i < n; i++){
        for (j = 0; j < (n/2) + 1; j++){
            if (j >= n / 2 - i && j >= i - n / 2){
                printf("*");
            }
            else
            printf(" ");
        }
        for (j = 0; j < n; j++){
            if (i == n / 2)
                printf("@");
            else
                printf(" ");
        }
        for (j = 0; j < (n / 2) + 1; j++){
            if (j >= n / 2 - i && j >= i - n / 2)
                printf("*");
        }
        printf("\n");
    }
    return 0;
}
 
// This code is contributed by shubhamsingh10

Java




// Java implementation
import java.util.*;
 
class GFG{
     
// Driver Code   
public static void main(String[] args)
{
    int n, i, j;
    Scanner s = new Scanner(System.in);
 
    n = s.nextInt();
       
    for(i = 0; i < (n / 2) + 2; i++)
    {
        for(j = 0; j < n - i; j++)
        {
            System.out.print(" ");
        }
        for(j = 0; j < 2 * i + 1; j++)
        {
            System.out.print("@"); 
        }
        System.out.println();
    }
       
    for(i = 0; i < n; i++)
    {
        for(j = 0; j < (n / 2) + 1; j++)
        {
            if (j >= n / 2 - i && j >= i - n / 2)
            {
                System.out.print("*");
            }
            else
            System.out.print(" ");
        }
        for(j = 0; j < n; j++)
        {
            if (i == n / 2)
                System.out.print("@");
            else
                System.out.print(" ");
        }
        for(j = 0; j < (n / 2) + 1; j++)
        {
            if (j >= n / 2 - i && j >= i - n / 2)
                System.out.print("*");
        }
        System.out.println();
    }
}
}
 
// This code is contributed by divyesh072019

Python3




# Python3 implementation
n=int(input())
 
for i in range(n//2+2):
    for j in range(n-i):
        print(" ",end="")
    for j in range(2*i+1):
        print("@",end="")
    print()
 
for i in range(n):
    for j in range(n//2+1):
        if (j>=n//2-i and j>=i-n//2):
            print("*",end="")
        else:
            print(" ",end="")
    for j in range(n):
        if i==n//2:
            print("@",end="")
        else:
            print(" ",end="")
    for j in range(n//2+1):
        if (j>=n//2-i and j>=i-n//2):
            print("*",end="")
    print()

C#




// C# implementation
using System;
class GFG {
  static void Main()
  {
       
    int n, i, j;
    string val;
    val = Console.ReadLine();
    n = Convert.ToInt32(val);
      
    for (i = 0; i < (n/2) + 2; i++)
    {
        for (j = 0; j < n - i; j++)
        {
            Console.Write(" ");
        }
        for (j = 0; j < 2 * i + 1; j++)
        {
            Console.Write("@");
        }
        Console.WriteLine();
    }
      
    for (i = 0; i < n; i++)
    {
        for (j = 0; j < (n/2) + 1; j++)
        {
            if (j >= n / 2 - i && j >= i - n / 2)
            {
                Console.Write("*");
            }
            else
            Console.Write(" ");
        }
        for (j = 0; j < n; j++)
        {
            if (i == n / 2)
                Console.Write("@");
            else
                Console.Write(" ");
        }
        for (j = 0; j < (n / 2) + 1; j++)
        {
            if (j >= n / 2 - i && j >= i - n / 2)
                Console.Write("*");
        }
        Console.WriteLine();
    }
  }
}
 
// This code is contributed by divyeshrabadiya07

Input: 

5

Output: 

     @
    @@@
   @@@@@
  @@@@@@@
  *     *
 **     **
***@@@@@***
 **     **
  *     *

 

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course. In case you are prepared, test your skills using TCS, Wipro, AmazonGoogle and Microsoft Test Serieses.




My Personal Notes arrow_drop_up
Recommended Articles
Page :