EaglePB2's Competitive Programming Writeups
  • Home Page
  • Why Python?
  • Why 10^9 + 7?
  • General Formatting Title
  • šŸ‡²šŸ‡¾CodeNection
    • 2021
      • Closed Cateogry
        • Attend Talks
        • Distant Relatives
        • Concert
        • Mamak
        • Fair Contest
      • Open Preliminary Round
        • f(Aibohphobia)^-1
        • Did they cheat?
        • Semester Breaks
      • Open Final Round
        • Ways 1
        • Circular Campus
        • A joke
        • 🄰Last year when life was better
        • Thank You Pizza
    • 2023
      • Test Round
        • Codey and Alphabetical Scoring
        • Codey and Binary Guesser
      • Preliminary Round
        • Codey and CodeNection
        • Codey and Hide-and-Seek
        • Codey and Math
        • Codey and Textbooks
        • Codey and Money
        • Codey and Team Selection
        • Codey and Painted Tree
        • Codey and Number Grid
        • Codey and Crimes
      • Final Round
        • Codey and CodeNection 2
        • Codey and Connection
        • Codey and Schedule
        • Codey and School Supplies
        • Codey and Zombies
        • Codey and Sightseeing
        • Codey and Apples
        • Codey and Facto
        • Codey and Zoey
    • 2024
      • Test Round
        • Codey and Sunday
        • Codey and Takoyaki
      • Preliminary Round
        • Codey and CodeNection
        • Codey and Pebbles
        • Codey and Spam
        • Codey and Coins
        • Codey and Rectangles
        • Codey and Manuscript
        • Codey and Recipes
        • Codey and Toy Kingdom
        • Codey and Peaks
      • Final Round
        • Codey and Exit
        • Codey and Gardening
        • Codey and Symbol
        • Codey and Rectangles 2
        • Codey and Jutsu
        • Codey and Toy Kingdom 2
        • Codey and Speeches
  • ABaKoDa
    • 2023
      • Round 1
        • Problem Letters
        • Problem Statistics
        • Rankings Order
        • Rankings Search
      • Round 2
        • Abakoda Letters
        • Borrowed Words
        • Kensorship
        • Duel Languages
  • Meta Coding Competitions
    • 2011
      • Qualification Round
        • Double Squares
        • Peg Game
        • Studious Student
      • Round 1A
        • Diversity Number
        • Turn on the Lights
        • Wine Tasting
      • Round 1B
        • Chess 2
        • Diminishing Circle
        • Slot Machine Hacker
      • Round 1C
        • N-Factorful
        • Polynomial Factoring
        • Risky Slide
      • Round 2
        • Bonus Assignments
        • Scott's New Trick
        • Studious Student II
      • Final Round
        • Alien Game
        • Party Time
        • Safest Place
  • EaglePB2's Special
    • Hong Kong Identity card
    • Cycle Prefix Averages
    • Word Squares
Powered by GitBook
On this page
  • Question
  • Input Format
  • Constraints
  • Output Format
  • Sample Inputs:
  1. CodeNection
  2. 2024
  3. Preliminary Round

Codey and CodeNection

https://www.hackerrank.com/contests/codenection-2024-preliminary-round-closed-category/challenges/cn24-1

PreviousPreliminary RoundNextCodey and Pebbles

Last updated 2 months ago

Question

Codey loves creating patterns with letters! Codey wants to print a right-aligned pattern consisting of n rows using the letters from the word CODENECTION. Help Codey to build this unique pattern.

Input Format

The first line contains an integer n, which represents the number of rows of the pattern.

Constraints

1≤n≤111 \le n \le 111≤n≤11

Output Format

Output the right-aligned pattern.

Sample Inputs:

Input

6

Output

     C
    CO
   COD
  CODE
 CODEN
CODENE

Explanation

When n is 6, the first 6 letters of the word CODENECTION is printed in a right-aligned pattern with 6 rows.


Solution - Python Cheats

The hardest part of this question is actually to print a right-aligned pattern. Luckily for Python, it does have a function to handle with this :D

Otherwise, receive the input, slice CODENECTION into an array with chars, loop it and print the char with range i [:i] + rjust() function.

Here's the solution:

t = int(input())
string = "CODENECTION"

for i in range(1, t+1):
    print(string[:i].rjust(t))
šŸ‡²šŸ‡¾