Created
September 20, 2016 01:52
HackerRank - Stryker world code sprint - study code - II
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.IO; | |
class Solution { | |
static void Main(String[] args) { | |
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */ | |
string[] header = Console.ReadLine().Split(' '); | |
int n = Int32.Parse(header[0]); | |
int m = Int32.Parse(header[1]); | |
//Maybe not best data class? Need to think about. | |
SortedList<int, int> zero_indexes = new SortedList<int, int>(); | |
int[] array_A = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); | |
for(int i = 0; i<n; i++){ | |
if(array_A[i] == 0){ | |
zero_indexes.Add(i, i); | |
} | |
} | |
for(int i = 0; i<m; i++){ | |
string[] line = Console.ReadLine().Split(' '); | |
if(line[0] == "1"){ | |
int goal = Int32.Parse(line[2]); | |
if(goal > zero_indexes.Count){ | |
Console.WriteLine("NO"); | |
}else{ | |
Console.WriteLine(zero_indexes.Values[goal-1]); | |
} | |
}else if(line[0] == "2"){ | |
int index = Int32.Parse(line[2]); | |
int val = Int32.Parse(line[3]); | |
if(zero_indexes.ContainsKey(index) && val != 0){ | |
zero_indexes.Remove(index); | |
}else if(!zero_indexes.ContainsKey(index) && val ==0){ | |
zero_indexes.Add(index, index); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment