We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
(* Enter your code here. Read input from STDIN. Print output to STDOUT *)letrecread_linesacc=tryletline=input_linestdin|>int_of_stringinread_lines(line::acc)withEnd_of_file->List.revacc;;letarr=read_lines[];;(* This commented code below increased space complexity in my previous submissionlet len = List.length arr;;let rec range start stop step acc = if start >= stop then List.rev acc else range (start + step) stop step (start :: acc);;let indices = range 0 len 1 [];;let pairs = List.combine indices arr;;*)(* Better code is here below *)letenumeratelst=List.mapi(funindexelem->(index,elem))lst;;letpairs=enumeratearr;;letresult=List.filter(fun(index,el)->indexmod2<>0)pairs;;let()=List.iter(fun(index,el)->print_endline(string_of_intel))result;;
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Filter Positions in a List
You are viewing a single comment's thread. Return to all comments →
Solution in OCaml