From f0aa77436b46f7b0123ea49f6e9346035e0a03df Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Thu, 19 Dec 2024 22:05:23 +0100 Subject: [PATCH] =?UTF-8?q?cs:=20add=20=C2=AB769.=20Max=20Chunks=20To=20Ma?= =?UTF-8?q?ke=20Sorted=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit URL: https://leetcode.com/problems/max-chunks-to-make-sorted/ Signed-off-by: Matej Focko --- cs/max-chunks-to-make-sorted.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 cs/max-chunks-to-make-sorted.cs diff --git a/cs/max-chunks-to-make-sorted.cs b/cs/max-chunks-to-make-sorted.cs new file mode 100644 index 0000000..424df01 --- /dev/null +++ b/cs/max-chunks-to-make-sorted.cs @@ -0,0 +1,16 @@ +public class Solution { + public int MaxChunksToSorted(int[] arr) { + var chunks = 0; + + var maximum = arr[0]; + for (int i = 0; i < arr.Length; ++i) { + maximum = Math.Max(maximum, arr[i]); + + if (maximum == i) { + ++chunks; + } + } + + return chunks; + } +}