6 kyu

Prefix Permutation

53 of 117medmelki

Description:

Given a sequence of integers of length n, print the number of prefix permutations within it.

A prefix permutation is an index P that satisfies :

  • 0 <= P < N
  • the sequence A[0], A[1], .....A[P] is a permutation of integers from 1 to P + 1

Example :

if given sequence is [2,1,3,5,4], then ...
  [2]         is NOT a permuation of [1]
  [2,1]       IS a permutation of [1,2]
  [2,1,3]     IS a permutation of [1,2,3]
  [2,1,3,5]   is NOT a permutation of [1,2,3,4]
  [2,1,3,5,4] IS a permutation of [1,2,3,4,5]

...and there are 3 prefix permutations  
Performance
Algorithms

Stats:

CreatedOct 20, 2017
PublishedOct 20, 2017
Warriors Trained379
Total Skips13
Total Code Submissions1377
Total Times Completed117
Java Completions53
JavaScript Completions68
Total Stars7
% of votes with a positive feedback rating84% of 41
Total "Very Satisfied" Votes32
Total "Somewhat Satisfied" Votes5
Total "Not Satisfied" Votes4
Total Rank Assessments11
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • medmelki Avatar
  • Voile Avatar
  • KenKamau Avatar
Ad