This file contains hidden or 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
| import java.util.ArrayList; | |
| import java.util.Comparator; | |
| import java.util.PriorityQueue; | |
| import java.util.Scanner; | |
| public class LittleElephantLemonade { | |
| private int drunkVolume; | |
| private ArrayList<PriorityQueue<Integer>> rooms; | |
| public LittleElephantLemonade() { | |
| drunkVolume=0; | |
| rooms=new ArrayList<PriorityQueue<Integer>>(); |
This file contains hidden or 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
| namespace java org.rfaisal.math | |
| namespace csharp Math | |
| service MathService{ | |
| i32 add (1:i32 a, 2:i32 b), | |
| i32 sub (1:i32 a, 2:i32 b), | |
| i32 mul (1:i32 a, 2:i32 b), | |
| i32 div (1:i32 a, 2:i32 b), | |
| i32 mod (1:i32 a, 2:i32 b) | |
| } |
This file contains hidden or 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
| public class MathServer | |
| { | |
| public MathServer() { } | |
| public int add(int a, int b) | |
| { | |
| Console.WriteLine("Called add({0},{1})={2}", a, b, a+b); | |
| return a + b; | |
| } | |
| public int sub(int a, int b) | |
| { |
This file contains hidden or 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
| public class MathServer : Math.MathService.Iface | |
| { | |
| public MathServer() { } | |
| public int add(int a, int b) | |
| { | |
| Console.WriteLine("Called add({0},{1})={2}", a, b, a+b); | |
| return a + b; | |
| } | |
| public int sub(int a, int b) | |
| { |
This file contains hidden or 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
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| try | |
| { | |
| MathServer handler = new MathServer(); | |
| MathService.Processor processor = new MathService.Processor(handler); | |
| TServerTransport serverTransport = new TServerSocket(9095); | |
| TServer server = new TSimpleServer(processor, serverTransport); |
This file contains hidden or 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
| public class MathClient { | |
| public static void main(String[] args) throws TException{ | |
| TTransport transport = new TSocket("localhost", 9095); | |
| transport.open(); | |
| TProtocol protocol = new TBinaryProtocol(transport); | |
| MathService.Client client = new MathService.Client(protocol); | |
| System.out.println(client.add(10, 20)); | |
| System.out.println(client.sub(10, 20)); | |
| System.out.println(client.mul(10, 20)); | |
| System.out.println(client.div(10, 20)); |
This file contains hidden or 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
| public class LittleElephantAndBooks { | |
| public static int getNumber(int[] pages, int number){ | |
| int littleElephantMax=find(pages,number);//selection algorithm, O(n) worst case | |
| int lazyElephantMax=0; | |
| int sum=0; | |
| for(int i=0;i<pages.length;i++){ //O(n) | |
| if(pages[i]<=littleElephantMax){ | |
| if(pages[i]>lazyElephantMax && pages[i]!=littleElephantMax){ | |
| lazyElephantMax=pages[i]; | |
| } |
This file contains hidden or 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
| public class FoxAndClassroom { | |
| public static String ableTo(int m, int n){ | |
| HashSet<Point> overallVisited=new HashSet<Point>(); | |
| for(int i=0;i<m;i++){ | |
| for(int j=0;j<n;j++){ | |
| Point cur=new Point(i,j); | |
| if(!overallVisited.contains(cur)){ | |
| HashSet<Point> visited=new HashSet<Point>(); | |
| while(!visited.contains(cur) && visited.size() < m*n){ | |
| visited.add(cur); |
This file contains hidden or 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
| public class BoundaryTraversal { | |
| public static ArrayList<TNode<Integer>> perform(TNode<Integer> root){ | |
| ArrayList<TNode<Integer>> ret= new ArrayList<TNode<Integer>>(); | |
| ret.addAll(traverseLeftSideTopDown(root)); | |
| ret.addAll(traverseBottomSideLeftRight(root)); | |
| if(root!=null){ | |
| ret.addAll(traverseRightSideBottomUp(root.right));//for excluding root | |
| } | |
| return ret; | |
| } |
This file contains hidden or 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
| public class MoveZerosToEnd { | |
| public static int[] move(int[] arr){ | |
| int current=0; | |
| for(int i=0;i<arr.length;i++){ | |
| if(arr[i]!=0) | |
| arr[current++]=arr[i]; | |
| } | |
| while(current<arr.length) | |
| arr[current++]=0; | |
| return arr; |