You are not logged in. Please login at www.codechef.com to post your questions!

×

CODE1604-Editorial

PROBLEM LINK:

Practice
Contest

Author: Ashish Ahuja
Tester: Ashish Ahuja
Editorialist: Ashish Ahuja

DIFFICULTY:

MEDIUM

PREREQUISITES:

String processing, Permutations & Combinations

PROBLEM:

The problem is based on the dictionary position of words formed randomly from the given string of letters.

QUICK EXPLANATION:

The programmer is required to place a letter out of the given letters, at the start of the string, and then find out dictionary position of the first and the last word formed with that letter at the beginning.

EXPLANATION:

Here, the only catch is to find out the dictionary position after successfully placing a letter at the start of the string. For instance, if 5 random letters are given -

 t z k i o 
Then the solution demands that you place one of the letters at the index '0' of the string. Let us take -
o
Now with, 'o' at the start there are 4! ways to place the rest of the letters.
We have to find out the first and the last way of these 4! ways, i.e. the first and the last word formed from these 5 letters with 'o' at the beginning of the string.
A small code snippet is as follows -
int fact(int n)
{

if(n==1)
    return(1);
else
    return(n*fact(n-1));

}

This function is used to find the number of ways to place the letters of the string with the position of the first letter fixed. Then, we use this function to give us the position of the first and the last words in the dictionary, which start and end with the specified letter.

AUTHOR'S AND TESTER'S SOLUTIONS:

Author's solution can be found here.
Tester's solution can be found here.

asked 24 Mar '16, 17:59

se_aashish's gravatar image

0★se_aashish
32
accept rate: 0%

edited 28 Mar '16, 14:17

admin's gravatar image

0★admin ♦♦
19.8k350498541


if n=26, of course you cannot use integer datatype only to compute 25!. It should use BigInteger.

link

answered 26 Dec '17, 20:01

dickynovanto's gravatar image

3★dickynovanto
1
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×15,645
×2,591
×887
×349
×181
×10
×4
×1

question asked: 24 Mar '16, 17:59

question was seen: 1,076 times

last updated: 26 Dec '17, 20:01