Find first missing positive: Difference between revisions

From Rosetta Code
Content added Content deleted
No edit summary
No edit summary
Line 1: Line 1:
{{Draft task}}
{{Draft task}}
Let given an unsorted integer array nums. The goal is find the smallest missing positive integer.
Let given an unsorted integer array nums. The goal is find the smallest missing positive integer.
<br> nums = [1,2,0],[3,4,-1,1],[7,8,9,11,12]
<br> nums = [1,2,0], [3,4,-1,1], [7,8,9,11,12]
=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>
<lang ring>
nums = [[1,2,0], [3,4,-1,1], [7,8,9,11,12]]
nums = [[1,2,0],[3,4,-1,1],[7,8,9,11,12]]
numnr = list(3)
numnr = list(3)
numnr[1] = "[1,2,0]"
numnr[1] = "[1,2,0]"

Revision as of 17:36, 23 February 2021

Find first missing positive is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

Let given an unsorted integer array nums. The goal is find the smallest missing positive integer.
nums = [1,2,0], [3,4,-1,1], [7,8,9,11,12]

Ring

<lang ring> nums = [[1,2,0],[3,4,-1,1],[7,8,9,11,12]] numnr = list(3) numnr[1] = "[1,2,0]" numnr[2] = "[3,4,-1,1]" numnr[3] = "[7,8,9,11,12]"

for n = 1 to len(nums)

   for m = 1 to len(nums[n])
       if nums[n][m] < 1
          del(nums[n],m)
       ok
   next
   sortNums = sort(nums[n])
   ln = len(sortNums)
   num = sortNums[ln]   
   for m = 1 to num + 1
       ind = find(nums[n],m)
       if ind < 1
          see "the smallest missing positive integer for " + numnr[n] + ": " + m + nl
          exit
       ok
   next

next </lang>

Output:
the smallest missing positive integer for [1,2,0]: 3
the smallest missing positive integer for [3,4,-1,1]: 2
the smallest missing positive integer for [7,8,9,11,12]: 1