0
Specification
This challenge is simple to state: your input is a non-empty array of nonnegative integers, and your task is to partition it into as few substrings as possible, such that each substring is a permutation of a consecutive integer range.
More formally, if the input array is A
, then the output is minimum number of partition of A
into B
(s):
- Each arrays
B
form a partition ofA
into substrings. Inductively, this means that eitherB
is the singleton array containing 1 element fromA
, or the elements ofB
is a subsequence ofA
, which when sorted are contiguous likex,x+1,x+2,..
. - The number of arrays
B
is minimal.
Example
Consider the input array A = [1,2,3,4,3,5]
.
Output is 2
One possible minimal partitions are B = [1,2,3],[4,3,5]
. That's the only partition to 2 substrings.
{4,3,5}
in sorted order is {3,4,5}
which is contiguous.
Input
An array of integers A
.
Output
A number, indicate the smallest number of parts A
can be splitted to.
Winning criteria
Your submissions will be scored in bytes, with less bytes being better.
1This site is for programming contests (i.e., you post programming challenges in questions), general programming questions are off-topic here. – user202729 – 2018-01-27T07:52:07.173
3(in other words, because the question is a question, it's off-topic. Counter-intuitive) – user202729 – 2018-01-27T07:52:55.993
Is this a code-golf? Maybe you should clarify and add a [tag:code-golf] tag. – alephalpha – 2018-01-27T08:04:07.717
I have edited your question to suit our standards. I have also added an objective winning criterion, namely [tag:code-golf]. Feel free to edit / rollback if you disagree with the changes I’ve made. Oh, and welcome to PPCG! – Mr. Xcoder – 2018-01-27T09:12:53.553
(well, this way you get completely-useless and very-short programs) – user202729 – 2018-01-27T09:19:37.763
@JonathanAllan "contiguous subsequence" is the same as "substring". – user202729 – 2018-01-27T09:28:19.140
2Is the example answer 2 because the minimal length of any possible
B
is 2 or because there are 2 such minima? Seems to be some conflict between "your task is to partition it into as few contiguous increasing subsequences as possible" vs "we have Q queries updating single value onA
asking minimum number of typeB
(s) possible" – Jonathan Allan – 2018-01-27T09:38:14.5531This challenge needs more test cases. I'd suggest
[]
,[3]
,[1,2]
,[2,5]
,[2,6,3]
,[1,2,11,12,3,4,9,20,22,10,5,6,14,13]
. – Zgarb – 2018-01-27T13:42:09.450Another test case:
[3,3,3,2,2,2]
– Zgarb – 2018-01-27T13:49:20.413I VTC as unclear since there seems to still be confusion regarding the specification. The examples do not match up with the literal meaning of the description. – Jonathan Allan – 2018-01-27T14:24:29.030
OP's question on SO might help for clarification. – ovs – 2018-01-27T14:25:01.870
@ovs the question here has probably mutated from its intent. A new, clear question (or even questions) would be better in my opinion. – Jonathan Allan – 2018-01-27T14:27:05.187
@ovs Actually that is also unclear to me. – Jonathan Allan – 2018-01-27T14:31:43.700
@ovs The pdf posted in discussion might though.
– Jonathan Allan – 2018-01-27T14:38:52.560link to my question : https://expirebox.com/download/d250698abbe222861fe450d7f0ee6297.html
– Optimus Prime – 2018-01-27T14:40:05.867@JonathanAllan Oh.... The challenge doesn't match with the PDF. In that case just keep the current challenge, because... we don't care about the OP's original problem. – user202729 – 2018-01-27T15:12:33.353
@user202729 Maybe my previous edit was right :p – Jonathan Allan – 2018-01-27T15:15:06.313
@JonathanAllan Anything remaining that's still unclear? – user202729 – 2018-01-27T15:23:49.320
@user202729 yeah
1,2,3,4,5
is not a substring of1,2,3,4,3,5
- if we go by the examples it should be "subsequence" and the word "contiguous" is just misleading; if we go for substrings then the example is wrong. Which one will lead to less answers being incorrect?! – Jonathan Allan – 2018-01-27T15:29:21.787@JonathanAllan Edited. – user202729 – 2018-01-27T15:30:50.327
why have you removed the Link to the PDF? – Optimus Prime – 2018-01-27T15:35:49.907
@OptimusPrime "Challenges should be self-contained, because links may expire, especially expirebox links." – user202729 – 2018-01-27T15:40:13.450
@user202729 Kotlin answer returns
3
for1,2,8,3,4,3,5,7
, a substring version would return1
whereas a subsequence version would return3
so probably the latter (unless also buggy). – Jonathan Allan – 2018-01-27T15:48:24.200