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.
<?php$_fp=fopen("php://stdin","r");/* Enter your code here. Read input from STDIN. Print output to STDOUT */$q=intval(trim(fgets(STDIN)));$array=[];for($t_itr=0;$t_itr<$q;$t_itr++){$s=rtrim(fgets(STDIN),"\r\n");$arr=array_map('intval',preg_split('//',$s,-1,PREG_SPLIT_NO_EMPTY));if($arr[0]==1&&!empty($arr[1])){array_unshift($array,$arr[1]);}elseif($arr[0]==2){array_pop($array);}elseif($arr[0]==3){echo$array[count($array)-1].PHP_EOL;}}fclose($_fp);?>
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Queues: A Tale of Two Stacks
You are viewing a single comment's thread. Return to all comments →
Solution in PHP