Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created September 20, 2016 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianminchen/63172e67001956e75abae02d079c668d to your computer and use it in GitHub Desktop.
Save jianminchen/63172e67001956e75abae02d079c668d to your computer and use it in GitHub Desktop.
HackerRank - Stryker world code sprint - study code - II
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