Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.