Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1106203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:45:20+00:00 2026-05-17T01:45:20+00:00

Statement Consider a string of length N consisting only of lowercase alphabets a-z. Let

  • 0

Statement

Consider a string of length N consisting only of lowercase alphabets a-z. Let s[i] be the character at the i-th position in the string (1-based). The string is a K-string if there are EXACTLY K values of i (1 <= i < N) such that s[i+1]<s[i] (we assume 'a'<'b'<'c'<...<'z'). Given K, find the shortest K-string. If there are multiple solutions, find the lexicographically earliest K-string.

Input

The first line contains the number of test cases T (1<= T <= 100). Each test case contains an integer K (≤ 100).
Output

Output

T lines, one for each test case, containing the required string. Use only lower-case letters a-z.

What i cant understand is the case of 27 to 100. I can simply use char array to compute the the problem
This isnt the whole algo. I am still trying……

#include<iostream>
using namespace std;
int main()
{
char s[]={'0','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
    int k;
    cin>>k;
    for(int i=k;i>=1;i--)
    {
      //cout<<s[i+1]<<">"<<s[i];
      if(s[i+1]>s[i])
       cout<<s[i];

    }
    system("pause");
    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T01:45:20+00:00Added an answer on May 17, 2026 at 1:45 am

    Shortest then lexicographically earliest.

    So the solutions will be :

    • ba : K = 1, length = 2
    • cba : K = 2, length = 3
    • dbca : : K = 3, length = 4
    • zyx….a : K = 25, length = 26
    • bazyx….a : K = 26, length = 28
    • bcazyx….a : K = 27, length = 29
    • ….
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

consider the following pgSQL statement: SELECT DISTINCT some_field FROM some_table WHERE some_field LIKE 'text%'
Consider the following MySQL statement SELECT AccountNumber, Currency, Balance FROM clients JOIN balances ON
Lets consider the following linq statement. var ctx = new MoviesContext(); var movies =
Consider the following code ResultSet rs = null; Statement st = null; try {
Is it safe to use the using statement on a (potentially) null object? Consider
Statement: Static member variables can be ONLY changed by static methods. Is this statement
Consider this: //members is a table. String sql=select * from members; Query query =
Consider string.Format() whose parameters are a string and, among others in the overload list,
a) What do we consider as a dynamic sql statement? Any sql statement that
Let's consider the following code in Java. package obj; final class First { public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.