├── .gitignore ├── .idea ├── misc.xml ├── modules.xml ├── runConfigurations.xml ├── uiDesigner.xml ├── vcs.xml └── workspace.xml ├── MachineCodingRound.iml ├── README.md ├── out └── production │ └── MachineCodingRound │ └── com │ └── lavakumar │ ├── bowlingalley │ ├── BowlingGameService.class │ ├── Main.class │ ├── constants │ │ └── AppConstants.class │ ├── factory │ │ └── BonusFactory.class │ ├── model │ │ ├── Bonus.class │ │ └── Player.class │ ├── problem-statement │ │ └── Multiplayer Bowling Alley.pdf │ ├── scoreboard │ │ ├── ScoreBoard.class │ │ └── ScoreBoardImpl.class │ └── strategy │ │ ├── DefaultStrategy.class │ │ ├── SparseStrategy.class │ │ ├── Strategy.class │ │ └── StrikeStrategy.class │ ├── designfacebook │ ├── Driver.class │ ├── ReadMe.md │ ├── exception │ │ └── UserPostException.class │ ├── model │ │ ├── Friends.class │ │ ├── Post.class │ │ ├── User.class │ │ └── UserRelations.class │ ├── repository │ │ ├── PostRepository.class │ │ ├── UserPostRepository.class │ │ └── UserRepository.class │ └── service │ │ ├── NewsFeedService.class │ │ ├── PostService.class │ │ ├── UserRelationsService.class │ │ └── UserService.class │ ├── elevator │ ├── Driver.class │ ├── Driver2.class │ ├── ElevatorSystemController.class │ ├── ProblemStatement.md │ ├── model │ │ ├── Direction.class │ │ ├── Elevator.class │ │ ├── ElevatorDoorState.class │ │ ├── ElevatorRequest.class │ │ ├── ElevatorStatus.class │ │ ├── InsideRequest.class │ │ └── OutsideRequest.class │ ├── service │ │ └── RequestScheduler.class │ ├── strategy │ │ ├── DirectionalBatchingStrategy.class │ │ ├── ElevatorAssignmentStrategy.class │ │ └── NearestElevatorStrategy.class │ └── util │ │ └── Constants.class │ ├── inmemorykvstore │ ├── Driver.class │ ├── KeyValueStore.class │ ├── Pair.class │ ├── ValueObject.class │ └── problem.md │ ├── middlewarerouter │ ├── Driver.class │ ├── Router.class │ ├── RouterImpl$TrieNode.class │ └── RouterImpl.class │ ├── parkinglot │ ├── Main$1.class │ ├── Main.class │ ├── entity │ │ ├── Command.class │ │ ├── DisplayType.class │ │ ├── ParkingFloor.class │ │ ├── ParkingLot.class │ │ ├── ParkingSlot.class │ │ ├── Vehicle.class │ │ └── VehicleType.class │ ├── repository │ │ └── ParkingDataRepository.class │ └── service │ │ └── ParkingLotService.class │ ├── ratelimiter │ ├── Config.class │ ├── Main.class │ ├── RateLimiterService.class │ ├── ThrotleRule.class │ ├── ThrotleRulesService.class │ ├── UserIdentificationService.class │ └── algorthims │ │ ├── LeakyBucket.class │ │ ├── RateLimiter.class │ │ ├── SlidingWindow.class │ │ └── TokenBucket.class │ ├── snakeandladder │ ├── Main.class │ ├── model │ │ ├── Dice.class │ │ ├── Entities.class │ │ ├── PairPosition.class │ │ └── Player.class │ └── service │ │ └── PlaySnakeAndLadder.class │ ├── snakeandladderoptimal │ ├── SnakeLadder.class │ ├── model │ │ ├── Game.class │ │ └── Player.class │ └── service │ │ └── SnakeLadderService.class │ ├── splitwise │ ├── Main$1.class │ ├── Main.class │ ├── model │ │ ├── ExpenseType.class │ │ ├── Type.class │ │ ├── User.class │ │ ├── expense │ │ │ ├── EqualExpense.class │ │ │ ├── ExactExpense.class │ │ │ ├── Expense.class │ │ │ ├── ExpenseData.class │ │ │ └── PercentageExpense.class │ │ └── split │ │ │ ├── EqualSplit.class │ │ │ ├── ExactSplit.class │ │ │ ├── PercentSplit.class │ │ │ └── Split.class │ ├── repository │ │ └── ExpenseRepository.class │ └── service │ │ ├── ExpenseService$1.class │ │ ├── ExpenseService.class │ │ ├── SplitWiseService.class │ │ └── UserService.class │ ├── tictactoe │ ├── Main.class │ ├── Main_Another.class │ ├── exceptions │ │ └── BoardException.class │ ├── mode │ │ ├── ConsolePrint.class │ │ └── Print.class │ ├── model │ │ ├── Board.class │ │ ├── PairPosition.class │ │ └── Player.class │ ├── service │ │ ├── PlayTicTacToe.class │ │ └── TicTacToeService.class │ └── validations │ │ └── GameValidator.class │ ├── trello │ ├── Main.class │ ├── model │ │ ├── BList.class │ │ ├── Board.class │ │ ├── Card.class │ │ ├── PRIVACY.class │ │ └── User.class │ └── service │ │ ├── BListService.class │ │ ├── BoardService.class │ │ ├── CardService.class │ │ └── impl │ │ ├── BListServiceImpl.class │ │ ├── BoardServcieImpl.class │ │ └── CardServcieImpl.class │ ├── uber_rider_flow │ ├── Main.class │ ├── model │ │ ├── Booking.class │ │ ├── BookingStatus.class │ │ ├── Cab.class │ │ ├── Location.class │ │ ├── Rider.class │ │ ├── VehicleFareEstimate.class │ │ └── VehicleType.class │ ├── service │ │ ├── BookingService.class │ │ ├── CabService.class │ │ └── RiderService.class │ └── strategy │ │ ├── PricingStrategy.class │ │ ├── VehicleTypePricingStrategy$1.class │ │ └── VehicleTypePricingStrategy.class │ └── uber_with_driver_flow │ ├── Main.class │ ├── models │ ├── Booking.class │ ├── Cab.class │ ├── Driver.class │ ├── Location.class │ ├── Rider.class │ └── enums │ │ ├── BookingStatus.class │ │ └── VehicleType.class │ ├── pricing │ ├── PricingStrategy.class │ ├── SurgePricingStrategy$1.class │ ├── SurgePricingStrategy.class │ ├── VehicleTypePricingStrategy$1.class │ └── VehicleTypePricingStrategy.class │ ├── service │ ├── BookingService.class │ ├── CabService.class │ ├── DriverService.class │ └── RiderService.class │ └── utils │ └── VehicleFareEstimate.class └── src └── com └── lavakumar ├── bowlingalley ├── BowlingGameService.java ├── Main.java ├── constants │ └── AppConstants.java ├── factory │ └── BonusFactory.java ├── model │ ├── Bonus.java │ └── Player.java ├── problem-statement │ └── Multiplayer Bowling Alley.pdf ├── scoreboard │ ├── ScoreBoard.java │ └── ScoreBoardImpl.java └── strategy │ ├── DefaultStrategy.java │ ├── SparseStrategy.java │ ├── Strategy.java │ └── StrikeStrategy.java ├── designfacebook ├── Driver.java ├── ReadMe.md ├── exception │ └── UserPostException.java ├── model │ ├── Friends.java │ ├── Post.java │ ├── User.java │ └── UserRelations.java ├── repository │ ├── PostRepository.java │ ├── UserPostRepository.java │ └── UserRepository.java └── service │ ├── NewsFeedService.java │ ├── PostService.java │ ├── UserRelationsService.java │ └── UserService.java ├── elevator ├── Driver.java ├── Driver2.java ├── ElevatorSystemController.java ├── ProblemStatement.md ├── model │ ├── Direction.java │ ├── Elevator.java │ ├── ElevatorDoorState.java │ ├── ElevatorRequest.java │ ├── ElevatorStatus.java │ ├── InsideRequest.java │ └── OutsideRequest.java ├── service │ └── RequestScheduler.java ├── strategy │ ├── DirectionalBatchingStrategy.java │ ├── ElevatorAssignmentStrategy.java │ └── NearestElevatorStrategy.java └── util │ └── Constants.java ├── inmemorykvstore ├── Driver.java ├── KeyValueStore.java ├── Pair.java ├── ValueObject.java └── problem.md ├── middlewarerouter ├── Driver.java ├── Router.java └── RouterImpl.java ├── parkinglot ├── Main.java ├── entity │ ├── Command.java │ ├── DisplayType.java │ ├── ParkingFloor.java │ ├── ParkingLot.java │ ├── ParkingSlot.java │ ├── Vehicle.java │ └── VehicleType.java ├── repository │ └── ParkingDataRepository.java └── service │ └── ParkingLotService.java ├── ratelimiter ├── Config.java ├── Main.java ├── RateLimiterService.java ├── ThrotleRule.java ├── ThrotleRulesService.java ├── UserIdentificationService.java └── algorthims │ ├── LeakyBucket.java │ ├── RateLimiter.java │ ├── SlidingWindow.java │ └── TokenBucket.java ├── snakeandladder ├── Main.java ├── model │ ├── Dice.java │ ├── Entities.java │ ├── PairPosition.java │ └── Player.java └── service │ └── PlaySnakeAndLadder.java ├── snakeandladderoptimal ├── SnakeLadder.java ├── model │ ├── Game.java │ └── Player.java └── service │ └── SnakeLadderService.java ├── splitwise ├── Main.java ├── model │ ├── ExpenseType.java │ ├── Type.java │ ├── User.java │ ├── expense │ │ ├── EqualExpense.java │ │ ├── ExactExpense.java │ │ ├── Expense.java │ │ ├── ExpenseData.java │ │ └── PercentageExpense.java │ └── split │ │ ├── EqualSplit.java │ │ ├── ExactSplit.java │ │ ├── PercentSplit.java │ │ └── Split.java ├── repository │ └── ExpenseRepository.java └── service │ ├── ExpenseService.java │ ├── SplitWiseService.java │ └── UserService.java ├── tictactoe ├── Main.java ├── Main_Another.java ├── exceptions │ └── BoardException.java ├── mode │ ├── ConsolePrint.java │ └── Print.java ├── model │ ├── Board.java │ ├── PairPosition.java │ └── Player.java ├── service │ ├── PlayTicTacToe.java │ └── TicTacToeService.java └── validations │ └── GameValidator.java ├── trello ├── Main.java ├── model │ ├── BList.java │ ├── Board.java │ ├── Card.java │ ├── PRIVACY.java │ └── User.java └── service │ ├── BListService.java │ ├── BoardService.java │ ├── CardService.java │ └── impl │ ├── BListServiceImpl.java │ ├── BoardServcieImpl.java │ └── CardServcieImpl.java ├── uber_rider_flow ├── Main.java ├── ProblemStatement.md ├── model │ ├── Booking.java │ ├── BookingStatus.java │ ├── Cab.java │ ├── Location.java │ ├── Rider.java │ ├── VehicleFareEstimate.java │ └── VehicleType.java ├── service │ ├── BookingService.java │ ├── CabService.java │ └── RiderService.java └── strategy │ ├── PricingStrategy.java │ └── VehicleTypePricingStrategy.java └── uber_with_driver_flow ├── Main.java ├── ProblemStatement.md ├── models ├── Booking.java ├── Cab.java ├── Driver.java ├── Location.java ├── Rider.java └── enums │ ├── BookingStatus.java │ └── VehicleType.java ├── pricing ├── PricingStrategy.java ├── SurgePricingStrategy.java └── VehicleTypePricingStrategy.java ├── service ├── BookingService.java ├── CabService.java ├── DriverService.java └── RiderService.java └── utils └── VehicleFareEstimate.java /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /MachineCodingRound.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/bowlingalley/BowlingGameService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/bowlingalley/BowlingGameService.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/bowlingalley/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/bowlingalley/Main.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/bowlingalley/constants/AppConstants.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/bowlingalley/constants/AppConstants.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/bowlingalley/factory/BonusFactory.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/bowlingalley/factory/BonusFactory.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/bowlingalley/model/Bonus.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/bowlingalley/model/Bonus.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/bowlingalley/model/Player.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/bowlingalley/model/Player.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/bowlingalley/problem-statement/Multiplayer Bowling Alley.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/bowlingalley/problem-statement/Multiplayer Bowling Alley.pdf -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/bowlingalley/scoreboard/ScoreBoard.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/bowlingalley/scoreboard/ScoreBoard.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/bowlingalley/scoreboard/ScoreBoardImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/bowlingalley/scoreboard/ScoreBoardImpl.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/bowlingalley/strategy/DefaultStrategy.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/bowlingalley/strategy/DefaultStrategy.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/bowlingalley/strategy/SparseStrategy.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/bowlingalley/strategy/SparseStrategy.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/bowlingalley/strategy/Strategy.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/bowlingalley/strategy/Strategy.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/bowlingalley/strategy/StrikeStrategy.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/bowlingalley/strategy/StrikeStrategy.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/designfacebook/Driver.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/designfacebook/Driver.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/designfacebook/ReadMe.md: -------------------------------------------------------------------------------- 1 | Design Facebook 2 | 3 | Question Description 4 | 5 | Design a simplified version of Facebook where users can create/delete posts, follow/unfollow another user and are able to see the most recent posts in the user's news feed. Following methods to be implemented: 6 | 7 | 8 | 9 | 1) createPost(userId, postId): Compose a new post. 10 | 11 | 2) getNewsFeed(userId): Retrieve the 10 most recent post ids in the user's news feed. Each item in the news feed must be posted by users who the user followed or by the user herself (Order -> most to least recent) 12 | 13 | 3) follow(followerId, followeeId): Follower follows a followee. 14 | 15 | 4) unfollow(followerId, followeeId): Follower unfollows a followee. 16 | 17 | 5) deletePost(userId, postId): Delete an existing post. 18 | 19 | 6) getNewsFeedPaginated(userId, pageNumber): Retrieve the most recent post ids in the user's news feed in a paginated manner. Each item in the news feed must be posted by users who the user followed or by the user herself (Order -> most to least recent) Assume pageSize= 2. 20 | 21 | 22 | 23 | Evaluation points : 24 | 25 | 1) Test cases passed 26 | 27 | 2) Code structuring and cleanliness 28 | 29 | 3) Scale and concurrency -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/designfacebook/exception/UserPostException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/designfacebook/exception/UserPostException.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/designfacebook/model/Friends.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/designfacebook/model/Friends.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/designfacebook/model/Post.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/designfacebook/model/Post.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/designfacebook/model/User.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/designfacebook/model/User.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/designfacebook/model/UserRelations.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/designfacebook/model/UserRelations.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/designfacebook/repository/PostRepository.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/designfacebook/repository/PostRepository.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/designfacebook/repository/UserPostRepository.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/designfacebook/repository/UserPostRepository.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/designfacebook/repository/UserRepository.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/designfacebook/repository/UserRepository.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/designfacebook/service/NewsFeedService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/designfacebook/service/NewsFeedService.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/designfacebook/service/PostService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/designfacebook/service/PostService.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/designfacebook/service/UserRelationsService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/designfacebook/service/UserRelationsService.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/designfacebook/service/UserService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/designfacebook/service/UserService.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/elevator/Driver.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/elevator/Driver.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/elevator/Driver2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/elevator/Driver2.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/elevator/ElevatorSystemController.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/elevator/ElevatorSystemController.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/elevator/ProblemStatement.md: -------------------------------------------------------------------------------- 1 | **Goal**: Design an elevator system that supports multiple elevators across multiple floors. 2 | 3 | Each elevator should be able to: 4 | 5 | 1. Accept floor requests from inside the elevator 6 | 2. Respond to external up/down calls from floors 7 | 3. Move up or down one floor at a time 8 | 4. Open/close doors when it reaches a destination floor 9 | 10 | The system should also: 11 | 12 | 1. Decide which elevator to assign for each external request 13 | 2. Optimize for minimum wait time and efficient movement 14 | 3. Handle requests even while elevators are in motion” 15 | 16 | You’ll model it in object-oriented design, write fully working code, 17 | and simulate how elevators behave under different inputs 18 | 19 | **Constraints** 20 | 21 | 1. Number of elevators: 4 22 | 2. Number of floors: 10 23 | 3. Each elevator has a current floor, direction (UP/DOWN/IDLE), and a queue of requests 24 | 4. Requests can come in any order, at any time 25 | 5. Each elevator can only move one floor per tick (we’ll simulate time in discrete steps) -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/elevator/model/Direction.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/elevator/model/Direction.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/elevator/model/Elevator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/elevator/model/Elevator.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/elevator/model/ElevatorDoorState.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/elevator/model/ElevatorDoorState.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/elevator/model/ElevatorRequest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/elevator/model/ElevatorRequest.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/elevator/model/ElevatorStatus.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/elevator/model/ElevatorStatus.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/elevator/model/InsideRequest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/elevator/model/InsideRequest.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/elevator/model/OutsideRequest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/elevator/model/OutsideRequest.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/elevator/service/RequestScheduler.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/elevator/service/RequestScheduler.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/elevator/strategy/DirectionalBatchingStrategy.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/elevator/strategy/DirectionalBatchingStrategy.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/elevator/strategy/ElevatorAssignmentStrategy.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/elevator/strategy/ElevatorAssignmentStrategy.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/elevator/strategy/NearestElevatorStrategy.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/elevator/strategy/NearestElevatorStrategy.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/elevator/util/Constants.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/elevator/util/Constants.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/inmemorykvstore/Driver.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/inmemorykvstore/Driver.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/inmemorykvstore/KeyValueStore.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/inmemorykvstore/KeyValueStore.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/inmemorykvstore/Pair.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/inmemorykvstore/Pair.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/inmemorykvstore/ValueObject.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/inmemorykvstore/ValueObject.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/inmemorykvstore/problem.md: -------------------------------------------------------------------------------- 1 | Problem Statement 2 | 3 | Design an In-Memory Key-Value Store like Redis. 4 | 5 | https://workat.tech/machine-coding/practice/design-key-value-store-6gz6cq124k65 6 | 7 | The key-value store should be thread-safe. -> 8 | 9 | HashMap -> concurrentHashMap 10 | 11 | get 12 | put 13 | search 14 | list 15 | delete 16 | 17 | "dsa_bootcamp": { "title": "DSA-Bootcamp", "price": 10000.00, "enrolled": "PENDING", "estimated_time": 30 } 18 | 19 | enrolled -> String ( PENDING) 20 | 21 | "sde_bootcamp": { "title": "SDE-Bootcamp", "price": 30000.00, "enrolled": false, "estimated_time": 30 } 22 | 23 | enrolled -> boolean ( false) 24 | -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/middlewarerouter/Driver.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/middlewarerouter/Driver.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/middlewarerouter/Router.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/middlewarerouter/Router.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/middlewarerouter/RouterImpl$TrieNode.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/middlewarerouter/RouterImpl$TrieNode.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/middlewarerouter/RouterImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/middlewarerouter/RouterImpl.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/parkinglot/Main$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/parkinglot/Main$1.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/parkinglot/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/parkinglot/Main.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/parkinglot/entity/Command.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/parkinglot/entity/Command.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/parkinglot/entity/DisplayType.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/parkinglot/entity/DisplayType.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/parkinglot/entity/ParkingFloor.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/parkinglot/entity/ParkingFloor.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/parkinglot/entity/ParkingLot.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/parkinglot/entity/ParkingLot.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/parkinglot/entity/ParkingSlot.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/parkinglot/entity/ParkingSlot.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/parkinglot/entity/Vehicle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/parkinglot/entity/Vehicle.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/parkinglot/entity/VehicleType.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/parkinglot/entity/VehicleType.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/parkinglot/repository/ParkingDataRepository.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/parkinglot/repository/ParkingDataRepository.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/parkinglot/service/ParkingLotService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/parkinglot/service/ParkingLotService.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/ratelimiter/Config.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/ratelimiter/Config.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/ratelimiter/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/ratelimiter/Main.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/ratelimiter/RateLimiterService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/ratelimiter/RateLimiterService.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/ratelimiter/ThrotleRule.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/ratelimiter/ThrotleRule.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/ratelimiter/ThrotleRulesService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/ratelimiter/ThrotleRulesService.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/ratelimiter/UserIdentificationService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/ratelimiter/UserIdentificationService.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/ratelimiter/algorthims/LeakyBucket.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/ratelimiter/algorthims/LeakyBucket.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/ratelimiter/algorthims/RateLimiter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/ratelimiter/algorthims/RateLimiter.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/ratelimiter/algorthims/SlidingWindow.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/ratelimiter/algorthims/SlidingWindow.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/ratelimiter/algorthims/TokenBucket.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/ratelimiter/algorthims/TokenBucket.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/snakeandladder/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/snakeandladder/Main.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/snakeandladder/model/Dice.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/snakeandladder/model/Dice.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/snakeandladder/model/Entities.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/snakeandladder/model/Entities.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/snakeandladder/model/PairPosition.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/snakeandladder/model/PairPosition.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/snakeandladder/model/Player.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/snakeandladder/model/Player.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/snakeandladder/service/PlaySnakeAndLadder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/snakeandladder/service/PlaySnakeAndLadder.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/snakeandladderoptimal/SnakeLadder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/snakeandladderoptimal/SnakeLadder.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/snakeandladderoptimal/model/Game.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/snakeandladderoptimal/model/Game.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/snakeandladderoptimal/model/Player.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/snakeandladderoptimal/model/Player.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/snakeandladderoptimal/service/SnakeLadderService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/snakeandladderoptimal/service/SnakeLadderService.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/splitwise/Main$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/splitwise/Main$1.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/splitwise/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/splitwise/Main.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/splitwise/model/ExpenseType.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/splitwise/model/ExpenseType.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/splitwise/model/Type.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/splitwise/model/Type.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/splitwise/model/User.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/splitwise/model/User.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/splitwise/model/expense/EqualExpense.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/splitwise/model/expense/EqualExpense.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/splitwise/model/expense/ExactExpense.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/splitwise/model/expense/ExactExpense.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/splitwise/model/expense/Expense.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/splitwise/model/expense/Expense.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/splitwise/model/expense/ExpenseData.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/splitwise/model/expense/ExpenseData.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/splitwise/model/expense/PercentageExpense.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/splitwise/model/expense/PercentageExpense.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/splitwise/model/split/EqualSplit.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/splitwise/model/split/EqualSplit.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/splitwise/model/split/ExactSplit.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/splitwise/model/split/ExactSplit.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/splitwise/model/split/PercentSplit.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/splitwise/model/split/PercentSplit.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/splitwise/model/split/Split.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/splitwise/model/split/Split.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/splitwise/repository/ExpenseRepository.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/splitwise/repository/ExpenseRepository.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/splitwise/service/ExpenseService$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/splitwise/service/ExpenseService$1.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/splitwise/service/ExpenseService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/splitwise/service/ExpenseService.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/splitwise/service/SplitWiseService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/splitwise/service/SplitWiseService.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/splitwise/service/UserService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/splitwise/service/UserService.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/tictactoe/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/tictactoe/Main.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/tictactoe/Main_Another.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/tictactoe/Main_Another.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/tictactoe/exceptions/BoardException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/tictactoe/exceptions/BoardException.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/tictactoe/mode/ConsolePrint.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/tictactoe/mode/ConsolePrint.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/tictactoe/mode/Print.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/tictactoe/mode/Print.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/tictactoe/model/Board.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/tictactoe/model/Board.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/tictactoe/model/PairPosition.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/tictactoe/model/PairPosition.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/tictactoe/model/Player.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/tictactoe/model/Player.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/tictactoe/service/PlayTicTacToe.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/tictactoe/service/PlayTicTacToe.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/tictactoe/service/TicTacToeService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/tictactoe/service/TicTacToeService.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/tictactoe/validations/GameValidator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/tictactoe/validations/GameValidator.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/trello/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/trello/Main.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/trello/model/BList.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/trello/model/BList.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/trello/model/Board.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/trello/model/Board.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/trello/model/Card.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/trello/model/Card.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/trello/model/PRIVACY.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/trello/model/PRIVACY.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/trello/model/User.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/trello/model/User.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/trello/service/BListService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/trello/service/BListService.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/trello/service/BoardService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/trello/service/BoardService.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/trello/service/CardService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/trello/service/CardService.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/trello/service/impl/BListServiceImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/trello/service/impl/BListServiceImpl.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/trello/service/impl/BoardServcieImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/trello/service/impl/BoardServcieImpl.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/trello/service/impl/CardServcieImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/trello/service/impl/CardServcieImpl.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/uber_rider_flow/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/uber_rider_flow/Main.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/uber_rider_flow/model/Booking.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/uber_rider_flow/model/Booking.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/uber_rider_flow/model/BookingStatus.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/uber_rider_flow/model/BookingStatus.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/uber_rider_flow/model/Cab.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/uber_rider_flow/model/Cab.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/uber_rider_flow/model/Location.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/uber_rider_flow/model/Location.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/uber_rider_flow/model/Rider.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/uber_rider_flow/model/Rider.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/uber_rider_flow/model/VehicleFareEstimate.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/uber_rider_flow/model/VehicleFareEstimate.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/uber_rider_flow/model/VehicleType.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/uber_rider_flow/model/VehicleType.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/uber_rider_flow/service/BookingService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/uber_rider_flow/service/BookingService.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/uber_rider_flow/service/CabService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/uber_rider_flow/service/CabService.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/uber_rider_flow/service/RiderService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/uber_rider_flow/service/RiderService.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/uber_rider_flow/strategy/PricingStrategy.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/uber_rider_flow/strategy/PricingStrategy.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/uber_rider_flow/strategy/VehicleTypePricingStrategy$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/uber_rider_flow/strategy/VehicleTypePricingStrategy$1.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/uber_rider_flow/strategy/VehicleTypePricingStrategy.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/uber_rider_flow/strategy/VehicleTypePricingStrategy.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/uber_with_driver_flow/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/uber_with_driver_flow/Main.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/uber_with_driver_flow/models/Booking.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/uber_with_driver_flow/models/Booking.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/uber_with_driver_flow/models/Cab.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/uber_with_driver_flow/models/Cab.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/uber_with_driver_flow/models/Driver.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/uber_with_driver_flow/models/Driver.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/uber_with_driver_flow/models/Location.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/uber_with_driver_flow/models/Location.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/uber_with_driver_flow/models/Rider.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/uber_with_driver_flow/models/Rider.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/uber_with_driver_flow/models/enums/BookingStatus.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/uber_with_driver_flow/models/enums/BookingStatus.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/uber_with_driver_flow/models/enums/VehicleType.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/uber_with_driver_flow/models/enums/VehicleType.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/uber_with_driver_flow/pricing/PricingStrategy.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/uber_with_driver_flow/pricing/PricingStrategy.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/uber_with_driver_flow/pricing/SurgePricingStrategy$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/uber_with_driver_flow/pricing/SurgePricingStrategy$1.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/uber_with_driver_flow/pricing/SurgePricingStrategy.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/uber_with_driver_flow/pricing/SurgePricingStrategy.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/uber_with_driver_flow/pricing/VehicleTypePricingStrategy$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/uber_with_driver_flow/pricing/VehicleTypePricingStrategy$1.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/uber_with_driver_flow/pricing/VehicleTypePricingStrategy.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/uber_with_driver_flow/pricing/VehicleTypePricingStrategy.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/uber_with_driver_flow/service/BookingService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/uber_with_driver_flow/service/BookingService.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/uber_with_driver_flow/service/CabService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/uber_with_driver_flow/service/CabService.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/uber_with_driver_flow/service/DriverService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/uber_with_driver_flow/service/DriverService.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/uber_with_driver_flow/service/RiderService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/uber_with_driver_flow/service/RiderService.class -------------------------------------------------------------------------------- /out/production/MachineCodingRound/com/lavakumar/uber_with_driver_flow/utils/VehicleFareEstimate.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/out/production/MachineCodingRound/com/lavakumar/uber_with_driver_flow/utils/VehicleFareEstimate.class -------------------------------------------------------------------------------- /src/com/lavakumar/bowlingalley/BowlingGameService.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.bowlingalley; 2 | 3 | import com.lavakumar.bowlingalley.model.Player; 4 | import com.lavakumar.bowlingalley.constants.AppConstants; 5 | 6 | import java.util.List; 7 | 8 | public class BowlingGameService { 9 | 10 | List players; 11 | Player winnerPlayer; 12 | 13 | public BowlingGameService(List players) { 14 | this.players = players; 15 | } 16 | 17 | public void startGame() { 18 | int maxScore = 0; 19 | for(Player player: players){ 20 | int standingPins = AppConstants.TOTAL_PINS; 21 | for (int index = 0; index < AppConstants.MAX_ROLLS; index++) { 22 | int numPinDown = takeShot(standingPins); 23 | standingPins -= numPinDown; 24 | // Every Frame 25 | if(index%2 == 0) { 26 | player.getScoreBoard().roll(numPinDown); 27 | } else { 28 | if(standingPins == 0){ 29 | // Frame Shift 30 | index++; 31 | } 32 | player.getScoreBoard().roll(numPinDown); 33 | standingPins = refillThePins(); 34 | } 35 | } 36 | int finalScore = player.getScoreBoard().score(); 37 | if (finalScore > maxScore) { 38 | maxScore = finalScore; 39 | winnerPlayer = player; 40 | } 41 | } 42 | } 43 | 44 | private int refillThePins() { 45 | return AppConstants.TOTAL_PINS; 46 | } 47 | 48 | public String getWinner() { 49 | winnerPlayer.setWin(true); 50 | return winnerPlayer.toString(); 51 | } 52 | 53 | private int takeShot(int standingPins) { 54 | return (int) (Math.random() * (standingPins + 1)); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/com/lavakumar/bowlingalley/Main.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.bowlingalley; 2 | 3 | import com.lavakumar.bowlingalley.model.Player; 4 | import com.lavakumar.bowlingalley.scoreboard.ScoreBoardImpl; 5 | 6 | import java.util.Arrays; 7 | import java.util.List; 8 | 9 | public class Main { 10 | public static void main(String[] args) { 11 | Player p1 = new Player(1,"Player1", new ScoreBoardImpl()); 12 | Player p2 = new Player(2, "Player2", new ScoreBoardImpl()); 13 | 14 | List players = Arrays.asList(p1,p2); 15 | BowlingGameService bowlingGameService = new BowlingGameService(players); 16 | 17 | bowlingGameService.startGame(); 18 | 19 | System.out.println(bowlingGameService.getWinner()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/com/lavakumar/bowlingalley/constants/AppConstants.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.bowlingalley.constants; 2 | 3 | public class AppConstants { 4 | public static final int MAX_ROLLS = 21; 5 | public static final int TOTAL_PINS = 10; 6 | public static final int TOTAL_SETS = 10; 7 | } 8 | -------------------------------------------------------------------------------- /src/com/lavakumar/bowlingalley/factory/BonusFactory.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.bowlingalley.factory; 2 | 3 | import com.lavakumar.bowlingalley.model.Bonus; 4 | import com.lavakumar.bowlingalley.strategy.DefaultStrategy; 5 | import com.lavakumar.bowlingalley.strategy.SparseStrategy; 6 | import com.lavakumar.bowlingalley.strategy.Strategy; 7 | import com.lavakumar.bowlingalley.strategy.StrikeStrategy; 8 | 9 | public class BonusFactory { 10 | public static Strategy getStrategy(Bonus bonus){ 11 | if(bonus.equals(Bonus.SPARE)){ 12 | return new SparseStrategy(); 13 | } else if(bonus.equals(Bonus.STRIKE)){ 14 | return new StrikeStrategy(); 15 | }else { 16 | return new DefaultStrategy(); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/com/lavakumar/bowlingalley/model/Bonus.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.bowlingalley.model; 2 | 3 | public enum Bonus { 4 | STRIKE, 5 | SPARE; 6 | } 7 | -------------------------------------------------------------------------------- /src/com/lavakumar/bowlingalley/model/Player.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.bowlingalley.model; 2 | 3 | import com.lavakumar.bowlingalley.scoreboard.ScoreBoard; 4 | 5 | public class Player { 6 | private int id; 7 | private String playerName; 8 | private final ScoreBoard scoreBoard; 9 | private boolean isWin; 10 | 11 | public Player(int id, String playerName, ScoreBoard scoreBoard){ 12 | this.id = id; 13 | this.playerName = playerName; 14 | this.isWin = false; 15 | this.scoreBoard = scoreBoard; 16 | } 17 | 18 | public String getPlayerName() { 19 | return playerName; 20 | } 21 | 22 | public void setPlayerName(String playerName) { 23 | this.playerName = playerName; 24 | } 25 | 26 | public int getId() { 27 | return id; 28 | } 29 | 30 | public void setId(int id) { 31 | this.id = id; 32 | } 33 | 34 | public void setWin(boolean win) { 35 | isWin = win; 36 | } 37 | public boolean getWin() { 38 | return isWin; 39 | } 40 | 41 | public ScoreBoard getScoreBoard(){ 42 | return scoreBoard; 43 | } 44 | 45 | 46 | @Override 47 | public String toString() { 48 | return "Player{" + 49 | "id=" + id + 50 | ", playerName='" + playerName + '\'' + 51 | ", score=" + scoreBoard.score()+ 52 | ", isWin=" + isWin + 53 | '}'; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/com/lavakumar/bowlingalley/problem-statement/Multiplayer Bowling Alley.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lavakumarThatisetti/Machine-Coding-Round/119e35589e754393f567ea2a28da5e4e7a13220d/src/com/lavakumar/bowlingalley/problem-statement/Multiplayer Bowling Alley.pdf -------------------------------------------------------------------------------- /src/com/lavakumar/bowlingalley/scoreboard/ScoreBoard.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.bowlingalley.scoreboard; 2 | 3 | public interface ScoreBoard { 4 | 5 | void roll(Integer noOfPins); 6 | 7 | Integer score(); 8 | } 9 | -------------------------------------------------------------------------------- /src/com/lavakumar/bowlingalley/scoreboard/ScoreBoardImpl.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.bowlingalley.scoreboard; 2 | 3 | import com.lavakumar.bowlingalley.factory.BonusFactory; 4 | import com.lavakumar.bowlingalley.model.Bonus; 5 | import com.lavakumar.bowlingalley.constants.AppConstants; 6 | 7 | public class ScoreBoardImpl implements ScoreBoard { 8 | 9 | private final int[] rolls; 10 | private Integer currentRoll = 0; 11 | 12 | public ScoreBoardImpl(){ 13 | rolls = new int[AppConstants.MAX_ROLLS]; 14 | } 15 | 16 | @Override 17 | public void roll(Integer noOfPins){ 18 | if (currentRoll == AppConstants.MAX_ROLLS - 1 && (rolls[currentRoll - 1] + rolls[currentRoll - 2] >= 10)) { 19 | return; 20 | } 21 | rolls[currentRoll++] = noOfPins; 22 | } 23 | 24 | @Override 25 | public Integer score(){ 26 | int totalScore = 0; 27 | int set = 0; 28 | for (int i = 0; i < AppConstants.TOTAL_SETS; i++) { 29 | if (isStrike(set)) { 30 | totalScore += AppConstants.TOTAL_PINS + BonusFactory.getStrategy(Bonus.STRIKE).bonus(); 31 | set += 2; 32 | } else if (isSpare(set)) { 33 | totalScore += AppConstants.TOTAL_PINS + BonusFactory.getStrategy(Bonus.SPARE).bonus(); 34 | set += 2; 35 | } else { 36 | totalScore += rolls[set] + rolls[set + 1]; 37 | set += 2; 38 | } 39 | } 40 | return totalScore + rolls[set]; 41 | } 42 | 43 | private boolean isStrike(int set) { 44 | return rolls[set] == 10; 45 | } 46 | 47 | private boolean isSpare(int set) { 48 | return rolls[set] + rolls[set + 1] == 10; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/com/lavakumar/bowlingalley/strategy/DefaultStrategy.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.bowlingalley.strategy; 2 | 3 | public class DefaultStrategy implements Strategy{ 4 | public static final Integer DEFAULT_BONUS = 1; 5 | @Override 6 | public int bonus() { 7 | return DEFAULT_BONUS; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/com/lavakumar/bowlingalley/strategy/SparseStrategy.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.bowlingalley.strategy; 2 | 3 | public class SparseStrategy implements Strategy{ 4 | public static final Integer SPARE_BONUS = 5; 5 | @Override 6 | public int bonus() { 7 | return SPARE_BONUS; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/com/lavakumar/bowlingalley/strategy/Strategy.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.bowlingalley.strategy; 2 | 3 | public interface Strategy { 4 | int bonus(); 5 | } 6 | -------------------------------------------------------------------------------- /src/com/lavakumar/bowlingalley/strategy/StrikeStrategy.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.bowlingalley.strategy; 2 | 3 | public class StrikeStrategy implements Strategy{ 4 | public static final Integer STRIKE_BONUS = 10; 5 | @Override 6 | public int bonus() { 7 | return STRIKE_BONUS; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/com/lavakumar/designfacebook/Driver.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.designfacebook; 2 | 3 | import com.lavakumar.designfacebook.repository.UserRepository; 4 | 5 | public class Driver { 6 | public static void main(String[] args) { 7 | 8 | UserRepository userRepository = new UserRepository(); 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/com/lavakumar/designfacebook/ReadMe.md: -------------------------------------------------------------------------------- 1 | Design Facebook 2 | 3 | Question Description 4 | 5 | Design a simplified version of Facebook where users can create/delete posts, follow/unfollow another user and are able to see the most recent posts in the user's news feed. Following methods to be implemented: 6 | 7 | 8 | 9 | 1) createPost(userId, postId): Compose a new post. 10 | 11 | 2) getNewsFeed(userId): Retrieve the 10 most recent post ids in the user's news feed. Each item in the news feed must be posted by users who the user followed or by the user herself (Order -> most to least recent) 12 | 13 | 3) follow(followerId, followeeId): Follower follows a followee. 14 | 15 | 4) unfollow(followerId, followeeId): Follower unfollows a followee. 16 | 17 | 5) deletePost(userId, postId): Delete an existing post. 18 | 19 | 6) getNewsFeedPaginated(userId, pageNumber): Retrieve the most recent post ids in the user's news feed in a paginated manner. Each item in the news feed must be posted by users who the user followed or by the user herself (Order -> most to least recent) Assume pageSize= 2. 20 | 21 | 22 | 23 | Evaluation points : 24 | 25 | 1) Test cases passed 26 | 27 | 2) Code structuring and cleanliness 28 | 29 | 3) Scale and concurrency -------------------------------------------------------------------------------- /src/com/lavakumar/designfacebook/exception/UserPostException.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.designfacebook.exception; 2 | 3 | public class UserPostException extends RuntimeException{ 4 | 5 | private final String message; 6 | 7 | public UserPostException(String message){ 8 | this.message = message; 9 | } 10 | 11 | @Override 12 | public String getMessage() { 13 | return message; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/com/lavakumar/designfacebook/model/Friends.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.designfacebook.model; 2 | 3 | public class Friends { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/com/lavakumar/designfacebook/model/Post.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.designfacebook.model; 2 | 3 | import java.util.Date; 4 | 5 | public class Post { 6 | private final int postId; 7 | private final int userId; 8 | private final String postTitle; 9 | private final Date postCreateTimeStamp; 10 | private Date postUpdateTimeStamp; 11 | 12 | public Post(int postId, int userId, String postTitle, Date postCreateTimeStamp) { 13 | this.postId = postId; 14 | this.userId = userId; 15 | this.postTitle = postTitle; 16 | this.postCreateTimeStamp = postCreateTimeStamp; 17 | } 18 | 19 | public int getPostId() { 20 | return postId; 21 | } 22 | 23 | public int getUserId() { 24 | return userId; 25 | } 26 | 27 | public String getPostTitle() { 28 | return postTitle; 29 | } 30 | 31 | public Date getPostCreateTimeStamp() { 32 | return postCreateTimeStamp; 33 | } 34 | 35 | public Date getPostUpdateTimeStamp() { 36 | return postUpdateTimeStamp; 37 | } 38 | 39 | public void setPostUpdateTimeStamp(Date postUpdateTimeStamp) { 40 | this.postUpdateTimeStamp = postUpdateTimeStamp; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/com/lavakumar/designfacebook/model/User.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.designfacebook.model; 2 | 3 | public class User { 4 | private final int userId; 5 | private final int userName; 6 | 7 | public User(int userId, int userName) { 8 | this.userId = userId; 9 | this.userName = userName; 10 | } 11 | 12 | public int getUserId() { 13 | return userId; 14 | } 15 | 16 | public int getUserName() { 17 | return userName; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/com/lavakumar/designfacebook/model/UserRelations.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.designfacebook.model; 2 | 3 | import java.util.HashSet; 4 | 5 | public class UserRelations { 6 | private final HashSet userFollower; 7 | private final HashSet userFollowing; 8 | 9 | public UserRelations(){ 10 | userFollower = new HashSet<>(); 11 | userFollowing = new HashSet<>(); 12 | } 13 | 14 | public HashSet getUserFollower() { 15 | return userFollower; 16 | } 17 | 18 | public HashSet getUserFollowing() { 19 | return userFollowing; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/com/lavakumar/designfacebook/repository/PostRepository.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.designfacebook.repository; 2 | 3 | import com.lavakumar.designfacebook.model.Post; 4 | import com.lavakumar.designfacebook.model.User; 5 | 6 | import java.util.HashMap; 7 | 8 | public class PostRepository { 9 | 10 | private final HashMap postHashMap = new HashMap<>(); 11 | 12 | public Post savePost(Post post){ 13 | 14 | if(postHashMap.get(post.getPostId())!=null){ 15 | postHashMap.put(post.getPostId(),post); 16 | } 17 | return post; 18 | } 19 | public Post deletePost(int postId){ 20 | if(postHashMap.get(postId)!=null){ 21 | return postHashMap.remove(postId); 22 | } 23 | return null; 24 | } 25 | public Post getPost(int postId){ 26 | return postHashMap.get(postId); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/com/lavakumar/designfacebook/repository/UserPostRepository.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.designfacebook.repository; 2 | 3 | import com.lavakumar.designfacebook.exception.UserPostException; 4 | import com.lavakumar.designfacebook.model.Post; 5 | 6 | import java.util.HashMap; 7 | import java.util.Set; 8 | import java.util.TreeSet; 9 | 10 | public class UserPostRepository { 11 | private final HashMap> userPostMap = new HashMap<>(); 12 | 13 | public void savePostToUser(Post post){ 14 | userPostMap.computeIfAbsent(post.getUserId(), k -> new TreeSet<>()); 15 | userPostMap.get(post.getUserId()).add(post.getPostId()); 16 | } 17 | public Boolean deletePostOfUser(int userId, int postId){ 18 | if(userPostMap.get(userId)==null){ 19 | throw new UserPostException("USER NOT FOUND"); 20 | } 21 | return userPostMap.get(userId).remove(postId); 22 | } 23 | 24 | public Set getAllPostsOfUser(int userId){ 25 | Set postIds = userPostMap.get(userId); 26 | return postIds; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/com/lavakumar/designfacebook/repository/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.designfacebook.repository; 2 | 3 | import com.lavakumar.designfacebook.model.User; 4 | 5 | import java.util.HashMap; 6 | 7 | public class UserRepository { 8 | private final HashMap userMap = new HashMap<>(); 9 | 10 | public User saveUser(User user){ 11 | if(userMap.get(user.getUserId())!=null){ 12 | userMap.put(user.getUserId(),user); 13 | } 14 | return user; 15 | } 16 | 17 | public User getUser(int userId){ 18 | return userMap.get(userId); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/com/lavakumar/designfacebook/service/NewsFeedService.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.designfacebook.service; 2 | 3 | import com.lavakumar.designfacebook.model.Post; 4 | import com.lavakumar.designfacebook.model.UserRelations; 5 | import com.lavakumar.designfacebook.repository.UserPostRepository; 6 | 7 | import java.util.Collection; 8 | import java.util.Collections; 9 | import java.util.HashSet; 10 | import java.util.List; 11 | import java.util.PriorityQueue; 12 | import java.util.Set; 13 | import java.util.TreeMap; 14 | import java.util.TreeSet; 15 | 16 | public class NewsFeedService { 17 | 18 | private final UserService userService; 19 | private final UserRelationsService userRelationsService; 20 | private final UserPostRepository userPostRepository; 21 | private final PostService postService; 22 | 23 | public NewsFeedService(UserService userService, 24 | UserRelationsService userRelationsService, 25 | UserPostRepository userPostRepository, 26 | PostService postService){ 27 | this.userService = userService; 28 | this.userRelationsService = userRelationsService; 29 | this.userPostRepository = userPostRepository; 30 | this.postService = postService; 31 | } 32 | 33 | public Collection getNewsFeed(int userId) { 34 | TreeMap latestNewsFeed = new TreeMap<>(); 35 | // Check UserId Present or not; 36 | if(userService.getUser(userId)!=null){ 37 | UserRelations userRelations = userRelationsService.getUserRelations(userId); 38 | HashSet userFollowing = userRelations.getUserFollowing(); 39 | for(Integer followerId: userFollowing){ 40 | Set allPostIds = userPostRepository.getAllPostsOfUser(followerId); 41 | for(Integer postId: allPostIds) 42 | latestNewsFeed.put(postId,postService.getPost(postId)); 43 | } 44 | } 45 | return latestNewsFeed.values(); 46 | } 47 | 48 | public List getNewsFeedPaginated(int userId, int pageNumber){ 49 | return null; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/com/lavakumar/designfacebook/service/PostService.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.designfacebook.service; 2 | 3 | import com.lavakumar.designfacebook.model.Post; 4 | import com.lavakumar.designfacebook.repository.PostRepository; 5 | import com.lavakumar.designfacebook.repository.UserPostRepository; 6 | import com.lavakumar.designfacebook.repository.UserRepository; 7 | 8 | 9 | public class PostService { 10 | 11 | private final PostRepository postRepository; 12 | private final UserRepository userRepository; 13 | private final UserPostRepository userPostRepository; 14 | 15 | public PostService(PostRepository postRepository,UserRepository userRepository, UserPostRepository userPostRepository ){ 16 | this.postRepository = postRepository; 17 | this.userRepository = userRepository; 18 | this.userPostRepository = userPostRepository; 19 | } 20 | 21 | public Post createPost(Post post){ 22 | // Check User 23 | if(userRepository.getUser(post.getUserId())!=null){ 24 | Post savedPost = postRepository.savePost(post); 25 | userPostRepository.savePostToUser(savedPost); 26 | return savedPost; 27 | } 28 | return null; 29 | } 30 | 31 | public boolean deletePost(int userId, int postId){ 32 | if(postRepository.deletePost(postId) != null){ 33 | return userPostRepository.deletePostOfUser(userId,postId); 34 | } 35 | return false; 36 | } 37 | 38 | public Post getPost(int postId){ 39 | return postRepository.getPost(postId); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/com/lavakumar/designfacebook/service/UserRelationsService.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.designfacebook.service; 2 | 3 | import com.lavakumar.designfacebook.model.UserRelations; 4 | 5 | 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | public class UserRelationsService { 10 | 11 | Map userRelationsMap; 12 | 13 | public UserRelationsService(){ 14 | this.userRelationsMap = new HashMap<>(); 15 | } 16 | 17 | 18 | public void FollowUser(int userId, int followingUserId) { 19 | UserRelations userRelations = userRelationsMap.get(userId); 20 | UserRelations followingUserRelations = userRelationsMap.get(followingUserId); 21 | 22 | userRelations.getUserFollowing().add(followingUserId); 23 | followingUserRelations.getUserFollower().add(userId); 24 | } 25 | 26 | public void UnFollowUser(int userId, int followingUserId){ 27 | UserRelations userRelations = userRelationsMap.get(userId); 28 | UserRelations followingUserRelations = userRelationsMap.get(followingUserId); 29 | 30 | userRelations.getUserFollowing().remove(followingUserId); 31 | followingUserRelations.getUserFollower().remove(userId); 32 | } 33 | 34 | public UserRelations getUserRelations(int userId){ 35 | return userRelationsMap.get(userId); 36 | } 37 | 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/com/lavakumar/designfacebook/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.designfacebook.service; 2 | 3 | import com.lavakumar.designfacebook.model.User; 4 | import com.lavakumar.designfacebook.repository.UserRepository; 5 | 6 | public class UserService { 7 | 8 | private final UserRepository userRepository; 9 | 10 | public UserService(UserRepository userRepository){ 11 | this.userRepository = userRepository; 12 | } 13 | 14 | public User createUser(User user){ 15 | return userRepository.saveUser(user); 16 | } 17 | 18 | public User getUser(int userId){ 19 | return userRepository.getUser(userId); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/com/lavakumar/elevator/Driver.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.elevator; 2 | 3 | import com.lavakumar.elevator.model.Direction; 4 | import com.lavakumar.elevator.model.OutsideRequest; 5 | import com.lavakumar.elevator.strategy.DirectionalBatchingStrategy; 6 | import com.lavakumar.elevator.strategy.NearestElevatorStrategy; 7 | 8 | public class Driver { 9 | public static void main(String[] args) throws InterruptedException { 10 | ElevatorSystemController controller = new ElevatorSystemController(2, 0, 10, new NearestElevatorStrategy()); // fewer elevators = easier to simulate busy state 11 | 12 | // Step 1: Initial load - make all elevators busy 13 | controller.handleExternalRequest(new OutsideRequest(1, Direction.UP)); // elevator needs to go all the way up 14 | controller.handleExternalRequest(new OutsideRequest(2, Direction.UP)); 15 | controller.handleExternalRequest(new OutsideRequest(3, Direction.UP)); 16 | 17 | // Step 2: Add internal destinations to keep them busy 18 | controller.getElevators().get(0).addInternalRequest(0); 19 | controller.getElevators().get(1).addInternalRequest(1); 20 | 21 | // Step 3: Submit a new request that will be forced into waiting queue 22 | controller.handleExternalRequest(new OutsideRequest(2, Direction.UP)); // all elevators already busy 23 | 24 | // Simulation loop to demonstrate queueing and retry 25 | for (int tick = 1; tick <= 20; tick++) { 26 | System.out.println("\n===== Tick " + tick + " ====="); 27 | controller.stepSimulation(); 28 | controller.printSystemStatus(); 29 | 30 | // Step 4 (Optional): Inject a delayed request mid-simulation 31 | if (tick == 5) { 32 | System.out.println("Injecting new request at tick 5 (floor 3)"); 33 | controller.handleExternalRequest(new OutsideRequest(3, Direction.UP)); 34 | } 35 | 36 | Thread.sleep(1000); // pause for clarity 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/com/lavakumar/elevator/Driver2.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.elevator; 2 | 3 | import com.lavakumar.elevator.model.Direction; 4 | import com.lavakumar.elevator.model.Elevator; 5 | import com.lavakumar.elevator.model.OutsideRequest; 6 | import com.lavakumar.elevator.strategy.DirectionalBatchingStrategy; 7 | import com.lavakumar.elevator.strategy.ElevatorAssignmentStrategy; 8 | import com.lavakumar.elevator.strategy.NearestElevatorStrategy; 9 | 10 | public class Driver2 { 11 | public static void main(String[] args) throws InterruptedException { 12 | // Switch between NearestElevatorStrategy and DirectionalBatchingStrategy here 13 | ElevatorAssignmentStrategy strategy = new DirectionalBatchingStrategy(); 14 | // ElevatorAssignmentStrategy strategy = new NearestElevatorStrategy(); 15 | 16 | ElevatorSystemController controller = new ElevatorSystemController(3, 0, 10, strategy); 17 | System.out.println("📊 Using strategy: " + strategy.getClass().getSimpleName()); 18 | 19 | // STEP 1: Manually set elevator initial positions (0, 3, 6) 20 | // We simulate this by adding a dummy request and moving each elevator once 21 | controller.getElevators().get(0).addInternalRequest(0); 22 | controller.getElevators().get(0).move(); // Floor 0 23 | 24 | controller.getElevators().get(1).addInternalRequest(3); 25 | while (controller.getElevators().get(1).getCurrentFloor() < 3) { 26 | controller.getElevators().get(1).move(); // Floor 3 27 | } 28 | 29 | controller.getElevators().get(2).addInternalRequest(6); 30 | while (controller.getElevators().get(2).getCurrentFloor() < 6) { 31 | controller.getElevators().get(2).move(); // Floor 6 32 | } 33 | 34 | // Clear their internal state so they are idle again 35 | controller.getElevators().forEach(Elevator::resetToIdle); 36 | 37 | // STEP 2: Fire external requests 38 | controller.handleExternalRequest(new OutsideRequest(2, Direction.UP)); // Expect: Elevator 0 39 | controller.handleExternalRequest(new OutsideRequest(4, Direction.UP)); // Expect: Elevator 1 OR Elevator 0 (if batching) 40 | controller.handleExternalRequest(new OutsideRequest(5, Direction.UP)); // Expect: Elevator 2 OR Elevator 0 (if batching) 41 | controller.handleExternalRequest(new OutsideRequest(7, Direction.DOWN)); // Expect: Elevator 2 42 | 43 | // STEP 3: Run simulation 44 | for (int tick = 1; tick <= 10; tick++) { 45 | System.out.println("\n=============================="); 46 | System.out.println(" ⏱️ Tick " + tick); 47 | System.out.println("=============================="); 48 | controller.stepSimulation(); 49 | controller.printSystemStatus(); 50 | Thread.sleep(1000); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/com/lavakumar/elevator/ProblemStatement.md: -------------------------------------------------------------------------------- 1 | **Goal**: Design an elevator system that supports multiple elevators across multiple floors. 2 | 3 | Each elevator should be able to: 4 | 5 | 1. Accept floor requests from inside the elevator 6 | 2. Respond to external up/down calls from floors 7 | 3. Move up or down one floor at a time 8 | 4. Open/close doors when it reaches a destination floor 9 | 10 | The system should also: 11 | 12 | 1. Decide which elevator to assign for each external request 13 | 2. Optimize for minimum wait time and efficient movement 14 | 3. Handle requests even while elevators are in motion” 15 | 16 | You’ll model it in object-oriented design, write fully working code, 17 | and simulate how elevators behave under different inputs 18 | 19 | **Constraints** 20 | 21 | 1. Number of elevators: 4 22 | 2. Number of floors: 10 23 | 3. Each elevator has a current floor, direction (UP/DOWN/IDLE), and a queue of requests 24 | 4. Requests can come in any order, at any time 25 | 5. Each elevator can only move one floor per tick (we’ll simulate time in discrete steps) -------------------------------------------------------------------------------- /src/com/lavakumar/elevator/model/Direction.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.elevator.model; 2 | 3 | public enum Direction { 4 | IDLE, 5 | UP, 6 | DOWN 7 | } 8 | -------------------------------------------------------------------------------- /src/com/lavakumar/elevator/model/ElevatorDoorState.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.elevator.model; 2 | 3 | public enum ElevatorDoorState { 4 | OPENING, 5 | OPEN, 6 | CLOSING, 7 | CLOSED 8 | } 9 | -------------------------------------------------------------------------------- /src/com/lavakumar/elevator/model/ElevatorRequest.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.elevator.model; 2 | 3 | public abstract class ElevatorRequest { 4 | protected final int floor; 5 | 6 | public ElevatorRequest(int floor) { 7 | this.floor = floor; 8 | } 9 | 10 | public int getFloor() { 11 | return floor; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/com/lavakumar/elevator/model/ElevatorStatus.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.elevator.model; 2 | 3 | import java.util.Set; 4 | 5 | public class ElevatorStatus { 6 | private final int id; 7 | private final int currentFloor; 8 | private final Direction direction; 9 | private final ElevatorDoorState doorState; 10 | private final Set pendingRequests; 11 | 12 | public ElevatorStatus(int id, int currentFloor, Direction direction, 13 | ElevatorDoorState doorState, Set pendingRequests) { 14 | this.id = id; 15 | this.currentFloor = currentFloor; 16 | this.direction = direction; 17 | this.doorState = doorState; 18 | this.pendingRequests = pendingRequests; 19 | } 20 | 21 | public int getId() { 22 | return id; 23 | } 24 | 25 | public int getCurrentFloor() { 26 | return currentFloor; 27 | } 28 | 29 | public Direction getDirection() { 30 | return direction; 31 | } 32 | 33 | public ElevatorDoorState getDoorState() { 34 | return doorState; 35 | } 36 | 37 | public Set getPendingRequests() { 38 | return pendingRequests; 39 | } 40 | 41 | @Override 42 | public String toString() { 43 | return "ElevatorStatus{" + 44 | "id=" + id + 45 | ", currentFloor=" + currentFloor + 46 | ", direction=" + direction + 47 | ", doorState=" + doorState + 48 | ", pendingRequests=" + pendingRequests + 49 | '}'; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/com/lavakumar/elevator/model/InsideRequest.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.elevator.model; 2 | 3 | public class InsideRequest extends ElevatorRequest { 4 | public InsideRequest(int floor) { 5 | super(floor); 6 | } 7 | 8 | @Override 9 | public String toString() { 10 | return "InsideRequest to floor " + floor; 11 | } 12 | } 13 | 14 | -------------------------------------------------------------------------------- /src/com/lavakumar/elevator/model/OutsideRequest.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.elevator.model; 2 | 3 | public class OutsideRequest extends ElevatorRequest { 4 | private final Direction direction; 5 | 6 | public OutsideRequest(int floor, Direction direction) { 7 | super(floor); 8 | this.direction = direction; 9 | } 10 | 11 | public Direction getDirection() { 12 | return direction; 13 | } 14 | 15 | @Override 16 | public String toString() { 17 | return "OutsideRequest at floor " + floor + " to go " + direction; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/com/lavakumar/elevator/service/RequestScheduler.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.elevator.service; 2 | 3 | import com.lavakumar.elevator.model.Direction; 4 | import com.lavakumar.elevator.model.Elevator; 5 | 6 | import java.util.List; 7 | 8 | public class RequestScheduler { 9 | 10 | public Elevator assignElevator(List elevators, int requestedFloor, Direction requestedDirection) { 11 | Elevator bestElevator = null; 12 | int minDistance = Integer.MAX_VALUE; 13 | 14 | for (Elevator elevator : elevators) { 15 | Direction dir = elevator.getDirection(); 16 | int currentFloor = elevator.getCurrentFloor(); 17 | 18 | if (elevator.isIdle()) { 19 | int distance = Math.abs(currentFloor - requestedFloor); 20 | if (distance < minDistance) { 21 | minDistance = distance; 22 | bestElevator = elevator; 23 | } 24 | } else if (dir == requestedDirection) { 25 | if ((dir == Direction.UP && currentFloor <= requestedFloor) || 26 | (dir == Direction.DOWN && currentFloor >= requestedFloor)) { 27 | int distance = Math.abs(currentFloor - requestedFloor); 28 | if (distance < minDistance) { 29 | minDistance = distance; 30 | bestElevator = elevator; 31 | } 32 | } 33 | } 34 | } 35 | 36 | // fallback: choose any idle elevator if nothing else matches 37 | if (bestElevator == null) { 38 | for (Elevator elevator : elevators) { 39 | if (elevator.isIdle()) { 40 | return elevator; 41 | } 42 | } 43 | } 44 | 45 | return bestElevator; 46 | } 47 | } 48 | 49 | -------------------------------------------------------------------------------- /src/com/lavakumar/elevator/strategy/DirectionalBatchingStrategy.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.elevator.strategy; 2 | 3 | import com.lavakumar.elevator.model.Direction; 4 | import com.lavakumar.elevator.model.Elevator; 5 | import com.lavakumar.elevator.model.OutsideRequest; 6 | 7 | import java.util.List; 8 | 9 | public class DirectionalBatchingStrategy implements ElevatorAssignmentStrategy { 10 | @Override 11 | public Elevator assign(List elevators, OutsideRequest request) { 12 | // 1. Prefer elevators already moving in the same direction toward the floor 13 | for (Elevator e : elevators) { 14 | if (e.getDirection() == request.getDirection()) { 15 | int curr = e.getCurrentFloor(); 16 | if ((request.getDirection() == Direction.UP && curr <= request.getFloor()) || 17 | (request.getDirection() == Direction.DOWN && curr >= request.getFloor())) { 18 | return e; // batch it! 19 | } 20 | } 21 | } 22 | 23 | // 2. Fall back to nearest idle 24 | for (Elevator e : elevators) { 25 | if (e.isIdle()) { 26 | return e; 27 | } 28 | } 29 | 30 | return null; 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /src/com/lavakumar/elevator/strategy/ElevatorAssignmentStrategy.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.elevator.strategy; 2 | 3 | import com.lavakumar.elevator.model.Elevator; 4 | import com.lavakumar.elevator.model.OutsideRequest; 5 | 6 | import java.util.List; 7 | 8 | public interface ElevatorAssignmentStrategy { 9 | Elevator assign(List elevators, OutsideRequest request); 10 | } 11 | -------------------------------------------------------------------------------- /src/com/lavakumar/elevator/strategy/NearestElevatorStrategy.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.elevator.strategy; 2 | 3 | import com.lavakumar.elevator.model.Direction; 4 | import com.lavakumar.elevator.model.Elevator; 5 | import com.lavakumar.elevator.model.OutsideRequest; 6 | 7 | import java.util.List; 8 | 9 | public class NearestElevatorStrategy implements ElevatorAssignmentStrategy { 10 | 11 | @Override 12 | public Elevator assign(List elevators, OutsideRequest request) { 13 | Elevator best = null; 14 | int minDistance = Integer.MAX_VALUE; 15 | int target = request.getFloor(); 16 | Direction dir = request.getDirection(); 17 | 18 | for (Elevator e : elevators) { 19 | int curr = e.getCurrentFloor(); 20 | if (e.isIdle() || (e.getDirection() == dir && 21 | ((dir == Direction.UP && curr <= target) || 22 | (dir == Direction.DOWN && curr >= target)))) { 23 | int dist = Math.abs(curr - target); 24 | if (dist < minDistance) { 25 | minDistance = dist; 26 | best = e; 27 | } 28 | } 29 | } 30 | return best; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/com/lavakumar/elevator/util/Constants.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.elevator.util; 2 | 3 | public class Constants { 4 | public static final int FLOORS = 40; 5 | public static final int ELEVATORS = 20; 6 | public static final int CAPACITY_OF_ELEVATOR = 5; 7 | } 8 | -------------------------------------------------------------------------------- /src/com/lavakumar/inmemorykvstore/Driver.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.inmemorykvstore; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class Driver { 7 | public static void main(String[] args) { 8 | 9 | KeyValueStore keyValueStore = new KeyValueStore(); 10 | 11 | List> dsaBootCamps = new ArrayList<>(); 12 | dsaBootCamps.add(new Pair<>("title", "DSA-Bootcamp")); 13 | dsaBootCamps.add(new Pair<>("price", "10000.00")); 14 | dsaBootCamps.add(new Pair<>("enrolled", "true")); 15 | dsaBootCamps.add(new Pair<>("estimated_time", "30")); 16 | 17 | keyValueStore.put("dsa_bootcamp", dsaBootCamps); 18 | 19 | 20 | System.out.println(keyValueStore.get("dsa_bootcamp")); 21 | 22 | System.out.println(keyValueStore.keys()); 23 | 24 | System.out.println(keyValueStore.search("estimated_time", "30")); 25 | 26 | List> sdeBootCamps = new ArrayList<>(); 27 | sdeBootCamps.add(new Pair<>("title", "SDE-Bootcamp")); 28 | sdeBootCamps.add(new Pair<>("price", "10000.00")); 29 | sdeBootCamps.add(new Pair<>("enrolled", "false")); 30 | sdeBootCamps.add(new Pair<>("estimated_time", "30")); 31 | 32 | keyValueStore.put("sde_bootcamp", sdeBootCamps); 33 | 34 | 35 | System.out.println(keyValueStore.keys()); 36 | 37 | System.out.println(keyValueStore.search("estimated_time", "30")); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/com/lavakumar/inmemorykvstore/Pair.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.inmemorykvstore; 2 | 3 | public class Pair { 4 | private final K k; 5 | private final V v; 6 | 7 | public Pair(K k, V v) { 8 | this.k = k; 9 | this.v = v; 10 | } 11 | 12 | public K getK() { 13 | return k; 14 | } 15 | 16 | public V getV() { 17 | return v; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/com/lavakumar/inmemorykvstore/ValueObject.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.inmemorykvstore; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class ValueObject { 7 | private final Map attributes; 8 | 9 | public ValueObject(Map attributes) { 10 | this.attributes = new HashMap<>(attributes); 11 | } 12 | 13 | public Map getAttributes() { 14 | return attributes; 15 | } 16 | 17 | @Override 18 | public String toString() { 19 | StringBuilder sb = new StringBuilder(); 20 | for(Map.Entry entry: attributes.entrySet()) { 21 | sb.append(entry.getKey()).append(":").append(entry.getValue()).append(","); 22 | } 23 | return sb.toString(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/com/lavakumar/inmemorykvstore/problem.md: -------------------------------------------------------------------------------- 1 | Problem Statement 2 | 3 | Design an In-Memory Key-Value Store like Redis. 4 | 5 | https://workat.tech/machine-coding/practice/design-key-value-store-6gz6cq124k65 6 | 7 | The key-value store should be thread-safe. -> 8 | 9 | HashMap -> concurrentHashMap 10 | 11 | get 12 | put 13 | search 14 | list 15 | delete 16 | 17 | "dsa_bootcamp": { "title": "DSA-Bootcamp", "price": 10000.00, "enrolled": "PENDING", "estimated_time": 30 } 18 | 19 | enrolled -> String ( PENDING) 20 | 21 | "sde_bootcamp": { "title": "SDE-Bootcamp", "price": 30000.00, "enrolled": false, "estimated_time": 30 } 22 | 23 | enrolled -> boolean ( false) 24 | -------------------------------------------------------------------------------- /src/com/lavakumar/middlewarerouter/Driver.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.middlewarerouter; 2 | 3 | import java.util.regex.Matcher; 4 | import java.util.regex.Pattern; 5 | 6 | public class Driver { 7 | public static void main(String[] args) { 8 | Router router = new RouterImpl(); 9 | 10 | router.withRoute("/bar", "result"); 11 | System.out.println(router.route("/bar")); // -> "result" 12 | 13 | router.withRoute("/bar/abc", "abc"); 14 | System.out.println(router.route("/bar/abc"));// -> "abc" 15 | System.out.println(router.route("/bar/abc/dd")); //-> null 16 | 17 | router.withRoute("/bar/abc/dd", "dd"); 18 | router.withRoute("/bar/abc1/cde/dd", "ee"); 19 | System.out.println(router.route("/bar/*/dd"));// -> "dd" 20 | System.out.println(router.route("/bar/*/cde/dd")); // -> "ee" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/com/lavakumar/middlewarerouter/Router.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.middlewarerouter; 2 | 3 | public interface Router { 4 | 5 | void withRoute(String path, String result); 6 | String route(String path); 7 | } 8 | -------------------------------------------------------------------------------- /src/com/lavakumar/middlewarerouter/RouterImpl.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.middlewarerouter; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | import java.util.Objects; 6 | import java.util.regex.Matcher; 7 | import java.util.regex.Pattern; 8 | 9 | public class RouterImpl implements Router { 10 | 11 | static class TrieNode { 12 | Map children; 13 | String value; 14 | 15 | TrieNode(){ 16 | children = new HashMap<>(); 17 | } 18 | } 19 | 20 | TrieNode root; 21 | RouterImpl(){ 22 | root = new TrieNode(); 23 | } 24 | 25 | @Override 26 | public void withRoute(String path, String result) { 27 | String[] paths = path.split("/"); 28 | insert(paths, result); 29 | } 30 | 31 | public void insert(String[] paths, String value){ 32 | TrieNode current = root; 33 | for(String path: paths){ 34 | TrieNode trieNode = current.children.get(path); 35 | if(trieNode == null){ 36 | trieNode = new TrieNode(); 37 | current.children.put(path, trieNode); 38 | } 39 | current = trieNode; 40 | } 41 | current.value = value; 42 | } 43 | 44 | 45 | @Override 46 | public String route(String path) { 47 | String[] paths = path.split("/"); 48 | TrieNode node = search(paths); 49 | return node == null ? null : node.value; 50 | } 51 | 52 | 53 | public TrieNode search(String[] paths){ 54 | return searchHelper(paths, root,0); 55 | } 56 | 57 | public TrieNode searchHelper(String[] paths, TrieNode root, int index){ 58 | TrieNode current = root; 59 | for(int i=index;i entry: current.children.entrySet()){ 62 | if(entry.getKey()!=null){ 63 | TrieNode wildcard = searchHelper(paths,entry.getValue(), i+1); 64 | if(wildcard != null){ 65 | return wildcard; 66 | } 67 | } 68 | } 69 | } 70 | TrieNode trieNode = current.children.get(paths[i]); 71 | if(trieNode == null){ 72 | return null; 73 | } 74 | current = trieNode; 75 | } 76 | return current; 77 | } 78 | 79 | 80 | } 81 | -------------------------------------------------------------------------------- /src/com/lavakumar/parkinglot/Main.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.parkinglot; 2 | 3 | import com.lavakumar.parkinglot.entity.Command; 4 | import com.lavakumar.parkinglot.entity.DisplayType; 5 | import com.lavakumar.parkinglot.entity.ParkingLot; 6 | import com.lavakumar.parkinglot.entity.VehicleType; 7 | import com.lavakumar.parkinglot.service.ParkingLotService; 8 | 9 | import java.util.Scanner; 10 | 11 | public class Main { 12 | public static void main(String[] args) { 13 | ParkingLotService parkingLotService = new ParkingLotService(); 14 | 15 | while (true) { 16 | Scanner scan = new Scanner(System.in); 17 | Command type = Command.of(scan.next()); 18 | switch (type) { 19 | case CREATE_PARKING_LOT: parkingLotService.createParkingLot(new ParkingLot(scan.next(),scan.nextInt(),scan.nextInt())); 20 | break; 21 | case PARK_VEHICLE: parkingLotService.parkVehicle(VehicleType.valueOf(scan.next()),scan.next(),scan.next()); 22 | break; 23 | case UNPARK_VEHICLE: parkingLotService.unParkVehicle(scan.next()); 24 | break; 25 | case DISPLAY: parkingLotService.display(DisplayType.of(scan.next()),VehicleType.valueOf(scan.next())); 26 | break; 27 | case EXIT: return; 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/com/lavakumar/parkinglot/entity/Command.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.parkinglot.entity; 2 | 3 | import java.util.HashMap; 4 | 5 | public enum Command { 6 | CREATE_PARKING_LOT("create_parking_lot"), 7 | DISPLAY("display"), 8 | PARK_VEHICLE("park_vehicle"), 9 | UNPARK_VEHICLE("unpark_vehicle"), 10 | EXIT("exit"); 11 | 12 | private final String command; 13 | 14 | Command(String s) { 15 | command = s; 16 | } 17 | 18 | public String toString() { 19 | return this.command; 20 | } 21 | 22 | private static final HashMap map = new HashMap<>(values().length, 1); 23 | 24 | static { 25 | for (Command c : values()) map.put(c.command, c); 26 | } 27 | 28 | public static Command of(String name){ 29 | return map.get(name); 30 | } 31 | 32 | 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/com/lavakumar/parkinglot/entity/DisplayType.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.parkinglot.entity; 2 | 3 | import java.util.HashMap; 4 | 5 | public enum DisplayType { 6 | FREE_COUNT("free_count"), 7 | FREE_SLOTS("free_slots"), 8 | OCCUPIED_SLOTS("occupied_slots"); 9 | 10 | private final String display; 11 | 12 | DisplayType(String s) { 13 | display = s; 14 | } 15 | 16 | public String toString() { 17 | return this.display; 18 | } 19 | 20 | private static final HashMap map = new HashMap<>(values().length, 1); 21 | 22 | static { 23 | for (DisplayType c : values()) map.put(c.display, c); 24 | } 25 | 26 | public static DisplayType of(String name){ 27 | return map.get(name); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/com/lavakumar/parkinglot/entity/ParkingFloor.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.parkinglot.entity; 2 | 3 | import java.util.List; 4 | 5 | public class ParkingFloor { 6 | List parkingSlots = null; 7 | 8 | public ParkingFloor(List parkingSlots){ 9 | this.parkingSlots = parkingSlots; 10 | 11 | } 12 | public List getParkingSlots() { 13 | return parkingSlots; 14 | } 15 | 16 | public void setParkingSlots(List parkingSlots) { 17 | this.parkingSlots = parkingSlots; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/com/lavakumar/parkinglot/entity/ParkingLot.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.parkinglot.entity; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class ParkingLot { 7 | String parkingLotId; 8 | int noOfFloors; 9 | int noOfSlotsPerFloor; 10 | List parkingFloors; 11 | 12 | public ParkingLot(String parkingLotId, int noOfFloors, int noOfSlotsPerFloor) { 13 | this.parkingLotId = parkingLotId; 14 | this.noOfFloors = noOfFloors; 15 | this.noOfSlotsPerFloor = noOfSlotsPerFloor; 16 | parkingFloors = new ArrayList<>(noOfFloors); 17 | } 18 | 19 | public String getParkingLotId() { 20 | return parkingLotId; 21 | } 22 | 23 | public void setParkingLotId(String parkingLotId) { 24 | this.parkingLotId = parkingLotId; 25 | } 26 | 27 | public int getNoOfFloors() { 28 | return noOfFloors; 29 | } 30 | 31 | public void setNoOfFloors(int noOfFloors) { 32 | this.noOfFloors = noOfFloors; 33 | } 34 | 35 | public int getNoOfSlotsPerFloor() { 36 | return noOfSlotsPerFloor; 37 | } 38 | 39 | public void setNoOfSlotsPerFloor(int noOfSlotsPerFloor) { 40 | this.noOfSlotsPerFloor = noOfSlotsPerFloor; 41 | } 42 | 43 | public List getParkingFloors() { 44 | return parkingFloors; 45 | } 46 | 47 | public void setParkingFloors(List parkingFloors) { 48 | this.parkingFloors = parkingFloors; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/com/lavakumar/parkinglot/entity/ParkingSlot.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.parkinglot.entity; 2 | 3 | public class ParkingSlot { 4 | int floorId; 5 | int slotId; 6 | Vehicle vehicle; 7 | boolean isFree; 8 | VehicleType vehicleType; 9 | 10 | public ParkingSlot(VehicleType vehicleType, boolean isFree,int slotId) { 11 | this.vehicleType = vehicleType; 12 | this.isFree = isFree; 13 | this.slotId = slotId; 14 | } 15 | 16 | public VehicleType getVehicleType() { 17 | return vehicleType; 18 | } 19 | 20 | public void setVehicleType(VehicleType vehicleType) { 21 | this.vehicleType = vehicleType; 22 | } 23 | 24 | public int getFloorId() { 25 | return floorId; 26 | } 27 | 28 | public void setFloorId(int floorId) { 29 | this.floorId = floorId; 30 | } 31 | 32 | public int getSlotId() { 33 | return slotId; 34 | } 35 | 36 | public void setSlotId(int slotId) { 37 | this.slotId = slotId; 38 | } 39 | 40 | public Vehicle getVehicle() { 41 | return vehicle; 42 | } 43 | 44 | public void setVehicle(Vehicle vehicle) { 45 | this.vehicle = vehicle; 46 | } 47 | 48 | public boolean isFree() { 49 | return isFree; 50 | } 51 | 52 | public void setFree(boolean free) { 53 | isFree = free; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/com/lavakumar/parkinglot/entity/Vehicle.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.parkinglot.entity; 2 | 3 | public class Vehicle { 4 | VehicleType vehicleType; 5 | ParkingSlot parkingSlot; 6 | String ticketId; 7 | String color; 8 | String vehicleRegisterNo; 9 | 10 | public Vehicle(VehicleType vehicleType, ParkingSlot parkingSlot, String color, String vehicleRegisterNo) { 11 | this.vehicleType = vehicleType; 12 | this.parkingSlot = parkingSlot; 13 | this.color = color; 14 | this.vehicleRegisterNo = vehicleRegisterNo; 15 | } 16 | 17 | public VehicleType getVehicleType() { 18 | return vehicleType; 19 | } 20 | 21 | public void setVehicleType(VehicleType vehicleType) { 22 | this.vehicleType = vehicleType; 23 | } 24 | 25 | public ParkingSlot getParkingSlot() { 26 | return parkingSlot; 27 | } 28 | 29 | public void setParkingSlot(ParkingSlot parkingSlot) { 30 | this.parkingSlot = parkingSlot; 31 | } 32 | 33 | public String getTicketId() { 34 | return ticketId; 35 | } 36 | 37 | public void setTicketId(String ticketId) { 38 | this.ticketId = ticketId; 39 | } 40 | 41 | public String getColor() { 42 | return color; 43 | } 44 | 45 | public void setColor(String color) { 46 | this.color = color; 47 | } 48 | 49 | public String getVehicleRegisterNo() { 50 | return vehicleRegisterNo; 51 | } 52 | 53 | public void setVehicleRegisterNo(String vehicleRegisterNo) { 54 | this.vehicleRegisterNo = vehicleRegisterNo; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/com/lavakumar/parkinglot/entity/VehicleType.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.parkinglot.entity; 2 | 3 | public enum VehicleType { 4 | TRUCK, 5 | BIKE, 6 | CAR; 7 | } 8 | -------------------------------------------------------------------------------- /src/com/lavakumar/parkinglot/repository/ParkingDataRepository.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.parkinglot.repository; 2 | 3 | import com.lavakumar.parkinglot.entity.ParkingFloor; 4 | import com.lavakumar.parkinglot.entity.ParkingSlot; 5 | import com.lavakumar.parkinglot.entity.VehicleType; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | public class ParkingDataRepository { 11 | 12 | List parkingSlotData; 13 | List parkingFloors; 14 | 15 | public List initializeData(int noOfFloors,int noOfSlots) { 16 | parkingFloors = new ArrayList<>(noOfFloors); 17 | for(int i=0;i parkingSlots = getAllParkingSlotData(i); 20 | parkingFloors.add(new ParkingFloor(parkingSlots)); 21 | } 22 | return parkingFloors; 23 | } 24 | 25 | public void initializeSlots(int noOfSlots) { 26 | parkingSlotData = new ArrayList<>(noOfSlots); 27 | if(noOfSlots>=1) 28 | parkingSlotData.add(getTruckData()); 29 | if(noOfSlots>=3) 30 | for(int i=1;i<3;i++) 31 | parkingSlotData.add(getBikeData(i)); 32 | if(noOfSlots>3) 33 | for(int i=3;i getAllParkingSlotData(int floorId){ 39 | parkingSlotData.forEach(parkingSlot -> parkingSlot.setFloorId(floorId)); 40 | return parkingSlotData; 41 | } 42 | 43 | private ParkingSlot getTruckData(){ 44 | return new ParkingSlot(VehicleType.TRUCK,true, 0); 45 | } 46 | private ParkingSlot getBikeData(int slotId){ 47 | return new ParkingSlot(VehicleType.BIKE,true,slotId); 48 | } 49 | private ParkingSlot getCarData(int slotId){ 50 | return new ParkingSlot(VehicleType.CAR,true,slotId); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/com/lavakumar/ratelimiter/Config.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.ratelimiter; 2 | 3 | public class Config { 4 | public static long maxBucketSize = 10; 5 | public static long refillRate = 10; 6 | public static int timeWindowInSeconds = 1; 7 | public static int bucketSize = 10; 8 | public static int leakyCapacity = 10; 9 | } 10 | -------------------------------------------------------------------------------- /src/com/lavakumar/ratelimiter/Main.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.ratelimiter; 2 | 3 | import java.util.concurrent.ExecutorService; 4 | import java.util.concurrent.Executors; 5 | import java.util.concurrent.ScheduledExecutorService; 6 | import java.util.concurrent.TimeUnit; 7 | 8 | public class Main { 9 | public static void main(String[] args) throws Exception { 10 | 11 | ThrotleRule rule = new ThrotleRule(); 12 | ThrotleRulesService throtleRulesService = ThrotleRulesService.getInstance(); 13 | throtleRulesService.createRule("client1", rule); 14 | 15 | UserIdentificationService request = new UserIdentificationService(); 16 | 17 | ExecutorService executor = Executors.newFixedThreadPool(1); 18 | 19 | ScheduledExecutorService scheduledExecutor = Executors.newScheduledThreadPool(5); 20 | 21 | Long startTime = System.currentTimeMillis(); 22 | 23 | // for (int i = 0; i < 12; i++) { 24 | // executor.execute(() -> { 25 | // System.out.println(" client1 "+Thread.currentThread().getName() + "--" + request.serveRequest("client1")); 26 | // // System.out.println(" client2 "+Thread.currentThread().getName() + "--" + handleRequest.serveRequest("client2")); 27 | // try { 28 | // Thread.sleep(10); 29 | // } catch (InterruptedException e) { 30 | // e.printStackTrace(); 31 | // } 32 | // }); 33 | // } 34 | Runnable r = () -> { 35 | System.out.println(" client1 " + Thread.currentThread().getName() + "--" + request.serveRequest("client1")); 36 | }; 37 | scheduledExecutor.scheduleAtFixedRate(r, 0, 50, TimeUnit.MILLISECONDS); 38 | executor.shutdown(); 39 | 40 | try { 41 | executor.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS); 42 | Long endTime = System.currentTimeMillis(); 43 | System.out.println("total time " + (endTime - startTime)); 44 | } catch (InterruptedException e) { 45 | e.printStackTrace(); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/com/lavakumar/ratelimiter/RateLimiterService.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.ratelimiter; 2 | 3 | import com.lavakumar.ratelimiter.algorthims.RateLimiter; 4 | import com.lavakumar.ratelimiter.algorthims.SlidingWindow; 5 | import com.lavakumar.ratelimiter.algorthims.TokenBucket; 6 | 7 | import java.util.HashMap; 8 | 9 | public class RateLimiterService { 10 | HashMap clientRulesCache; 11 | HashMap rateLimiterHashMap; 12 | ThrotleRulesService throtleRulesService; 13 | 14 | public RateLimiterService(){ 15 | this.throtleRulesService = ThrotleRulesService.getInstance(); 16 | this.clientRulesCache = new HashMap<>(); 17 | this.rateLimiterHashMap = new HashMap<>(); 18 | } 19 | 20 | 21 | public boolean isRateLimitedUserRequest(String userId){ 22 | createUserIfNotTheir(userId); 23 | return rateLimiterHashMap.get(userId).allowRequest(); 24 | } 25 | 26 | private void createUserIfNotTheir(String userId){ 27 | if(!clientRulesCache.containsKey(userId)){ 28 | ThrotleRule clientRules = throtleRulesService.getClientRules(userId); 29 | clientRulesCache.put(userId, clientRules); 30 | } 31 | if(!rateLimiterHashMap.containsKey(userId)){ 32 | ThrotleRule throtleRule = clientRulesCache.get(userId); 33 | RateLimiter rateLimiter = new TokenBucket(throtleRule.getBucketSize(), throtleRule.getRefillRate()); 34 | rateLimiterHashMap.put(userId,rateLimiter); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/com/lavakumar/ratelimiter/ThrotleRule.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.ratelimiter; 2 | 3 | public class ThrotleRule { 4 | public long bucketSize; 5 | public long refillRate; 6 | 7 | public ThrotleRule(){ 8 | this.bucketSize = 10; 9 | this.refillRate = 10; 10 | } 11 | 12 | public ThrotleRule(long bucketSize, long refillRate) { 13 | this.bucketSize = bucketSize; 14 | this.refillRate = refillRate; 15 | } 16 | 17 | public long getBucketSize() { 18 | return bucketSize; 19 | } 20 | 21 | public long getRefillRate() { 22 | return refillRate; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/com/lavakumar/ratelimiter/ThrotleRulesService.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.ratelimiter; 2 | 3 | 4 | import java.util.HashMap; 5 | 6 | public class ThrotleRulesService { 7 | HashMap clientThrotleRules; 8 | private static volatile ThrotleRulesService instance; 9 | 10 | public ThrotleRulesService(){ 11 | clientThrotleRules = new HashMap<>(); 12 | } 13 | 14 | public void createRule(String clientId, ThrotleRule throtleRule){ 15 | clientThrotleRules.put(clientId, throtleRule); 16 | } 17 | 18 | public ThrotleRule getClientRules(String clientId){ 19 | return clientThrotleRules.get(clientId); 20 | } 21 | 22 | public static ThrotleRulesService getInstance(){ 23 | 24 | if (instance == null) { 25 | synchronized (ThrotleRulesService.class) { 26 | // Double check 27 | if (instance == null) { 28 | instance = new ThrotleRulesService(); 29 | } 30 | } 31 | } 32 | return instance; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/com/lavakumar/ratelimiter/UserIdentificationService.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.ratelimiter; 2 | 3 | 4 | public class UserIdentificationService { 5 | 6 | RateLimiterService rateLimiterService; 7 | 8 | public UserIdentificationService(){ 9 | this.rateLimiterService = new RateLimiterService(); 10 | } 11 | public String serveRequest(String clientId){ 12 | 13 | boolean isAllowed = rateLimiterService.isRateLimitedUserRequest(clientId); 14 | if(isAllowed){ 15 | return "Request Served"; 16 | } else return "Too Many Requests please try again"; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/com/lavakumar/ratelimiter/algorthims/LeakyBucket.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.ratelimiter.algorthims; 2 | 3 | 4 | import com.lavakumar.ratelimiter.Config; 5 | 6 | import java.util.concurrent.BlockingQueue; 7 | import java.util.concurrent.LinkedBlockingQueue; 8 | 9 | public class LeakyBucket implements RateLimiter { 10 | BlockingQueue queue; 11 | 12 | public LeakyBucket() { 13 | this.queue = new LinkedBlockingQueue<>(Config.leakyCapacity); 14 | } 15 | 16 | @Override 17 | public synchronized boolean allowRequest() { 18 | if(queue.remainingCapacity() > 0){ 19 | queue.add(1); 20 | return true; 21 | } 22 | return false; 23 | } 24 | } -------------------------------------------------------------------------------- /src/com/lavakumar/ratelimiter/algorthims/RateLimiter.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.ratelimiter.algorthims; 2 | 3 | public interface RateLimiter { 4 | boolean allowRequest(); 5 | } 6 | -------------------------------------------------------------------------------- /src/com/lavakumar/ratelimiter/algorthims/SlidingWindow.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.ratelimiter.algorthims; 2 | 3 | 4 | import java.util.Queue; 5 | import java.util.concurrent.ConcurrentLinkedQueue; 6 | /* 7 | F ..... R 8 | */ 9 | public class SlidingWindow implements RateLimiter { 10 | Queue queue; 11 | long timeWindowInSeconds; 12 | long bucketSize; 13 | 14 | public SlidingWindow(long bucketSize, long timeWindowInSeconds) { 15 | this.timeWindowInSeconds = timeWindowInSeconds; 16 | this.bucketSize = bucketSize; 17 | this.queue = new ConcurrentLinkedQueue(); 18 | } 19 | 20 | @Override 21 | public synchronized boolean allowRequest() { 22 | Long currentTime = System.currentTimeMillis(); 23 | checkAndUpdateWindow(currentTime); 24 | if(queue.size() < bucketSize){ 25 | queue.offer(currentTime); 26 | return true; 27 | } 28 | return false; 29 | } 30 | // Will remove all timestamps which fall behind greater than 1 sec 31 | public void checkAndUpdateWindow(Long currentTime){ 32 | if(queue.isEmpty()) return; 33 | 34 | long time = (currentTime - queue.peek())/1000; 35 | System.out.println("Time "+time); 36 | while (!queue.isEmpty() && time >= timeWindowInSeconds){ 37 | queue.poll(); 38 | System.out.println("QueuePeekTime "+queue.peek()); 39 | if(!queue.isEmpty()) time = (currentTime - queue.peek())/1000; 40 | } 41 | } 42 | } 43 | 44 | // [ 0.2, 0.3..... 1.0, 1.1] = 1.1 -0.2 = 0.9 -------------------------------------------------------------------------------- /src/com/lavakumar/ratelimiter/algorthims/TokenBucket.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.ratelimiter.algorthims; 2 | 3 | 4 | /* 5 | 10 , 10 , <=10, 6 | */ 7 | public class TokenBucket implements RateLimiter { 8 | private final long maxBucketSize; 9 | private final long refillRate; 10 | private double currentBucketSize; 11 | private long lastRefillTimeStamp; 12 | 13 | public TokenBucket(long maxBucketSize, long refillRate){ 14 | this.maxBucketSize = maxBucketSize; 15 | this.refillRate = refillRate; 16 | currentBucketSize = maxBucketSize; 17 | lastRefillTimeStamp = System.nanoTime(); 18 | } 19 | 20 | @Override 21 | public synchronized boolean allowRequest(){ 22 | refill(); 23 | if(currentBucketSize>=1){ 24 | currentBucketSize-=1; 25 | // System.out.print(" current bucket Size: "+currentBucketSize); 26 | return true; 27 | } 28 | return false; 29 | } 30 | 31 | private void refill(){ 32 | long now = System.nanoTime(); 33 | double tokensToAdd = (now-lastRefillTimeStamp)*refillRate/1e9; 34 | System.out.print("before refilled : "+currentBucketSize+" "); 35 | currentBucketSize = Math.min(currentBucketSize+tokensToAdd, maxBucketSize); 36 | System.out.print("After refilled : "+currentBucketSize); 37 | lastRefillTimeStamp = now; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/com/lavakumar/snakeandladder/Main.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.snakeandladder; 2 | 3 | import com.lavakumar.snakeandladder.model.Entities; 4 | import com.lavakumar.snakeandladder.service.PlaySnakeAndLadder; 5 | 6 | import java.util.Scanner; 7 | 8 | public class Main { 9 | public static void main(String[] args) { 10 | Scanner scan = new Scanner(System.in); 11 | Entities entities = Entities.getInstance(); 12 | 13 | int noOfSnakes = scan.nextInt(); 14 | while(noOfSnakes>0){ 15 | int startPosition = scan.nextInt(); 16 | int endPosition = scan.nextInt(); 17 | entities.setSnake(startPosition, endPosition); 18 | noOfSnakes--; 19 | } 20 | int noOfLadders = scan.nextInt(); 21 | while(noOfLadders>0){ 22 | int startPosition = scan.nextInt(); 23 | int endPosition = scan.nextInt(); 24 | entities.setLadder(startPosition, endPosition); 25 | noOfLadders--; 26 | } 27 | int noOfPlayers = scan.nextInt(); 28 | int i=0; 29 | while(noOfPlayers>0){ 30 | String player = scan.next(); 31 | entities.setPlayer(i++, player); 32 | noOfPlayers--; 33 | } 34 | PlaySnakeAndLadder playSnakeAndLadder = new PlaySnakeAndLadder(6); 35 | System.out.println(playSnakeAndLadder.PlayGame()+" wins the game"); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/com/lavakumar/snakeandladder/model/Dice.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.snakeandladder.model; 2 | 3 | import java.util.Random; 4 | 5 | public class Dice { 6 | private int numberOfDice; 7 | private static int MIN = 1; 8 | Random random; 9 | public Dice(int numberOfDice){ 10 | random = new Random(); 11 | this.numberOfDice = numberOfDice; 12 | } 13 | 14 | public int getNumberOfDice() { 15 | return random.nextInt((this.numberOfDice - MIN) + 1) + 1; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/com/lavakumar/snakeandladder/model/Entities.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.snakeandladder.model; 2 | 3 | import java.util.HashMap; 4 | 5 | public class Entities { 6 | static HashMap snakes; 7 | static HashMap ladders; 8 | static HashMap players; 9 | static Entities instance = null; 10 | 11 | public Entities(){ 12 | snakes = new HashMap<>(); 13 | ladders = new HashMap<>(); 14 | players = new HashMap<>(); 15 | } 16 | 17 | public void setSnake(int startPosition, int endPosition) { 18 | snakes.put(startPosition,endPosition); 19 | } 20 | 21 | public HashMap getSnakes() { 22 | return snakes; 23 | } 24 | 25 | public void setLadder(int startPosition, int endPosition) { 26 | ladders.put(startPosition,endPosition); 27 | } 28 | 29 | public HashMap getLadders() { 30 | return ladders; 31 | } 32 | 33 | public void setPlayer(int index,String playerName) { 34 | players.put(index,playerName); 35 | } 36 | 37 | public HashMap getPlayers() { 38 | return players; 39 | } 40 | 41 | public static Entities getInstance(){ 42 | if( instance == null){ 43 | instance = new Entities(); 44 | } 45 | return instance; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/com/lavakumar/snakeandladder/model/PairPosition.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.snakeandladder.model; 2 | 3 | public class PairPosition { 4 | int start; 5 | int end; 6 | 7 | public PairPosition(int start, int end) { 8 | this.start = start; 9 | this.end = end; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/com/lavakumar/snakeandladder/model/Player.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.snakeandladder.model; 2 | 3 | public class Player { 4 | private String playerName; 5 | private int id; 6 | public Player(String playerName,int id){ 7 | this.id = id; 8 | this.playerName = playerName; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/com/lavakumar/snakeandladder/service/PlaySnakeAndLadder.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.snakeandladder.service; 2 | 3 | import com.lavakumar.snakeandladder.model.Dice; 4 | import com.lavakumar.snakeandladder.model.Entities; 5 | import com.lavakumar.snakeandladder.model.PairPosition; 6 | 7 | import java.util.HashMap; 8 | 9 | 10 | public class PlaySnakeAndLadder { 11 | HashMap playerHistory; 12 | HashMap playerLatestPosition; 13 | Entities entities; 14 | Dice dice; 15 | public PlaySnakeAndLadder(int N){ 16 | playerHistory = new HashMap<>(); 17 | playerLatestPosition = new HashMap<>(); 18 | entities = Entities.getInstance(); 19 | dice = new Dice(N); 20 | 21 | } 22 | public String PlayGame() { 23 | initilizePlayersStartValue(); 24 | int i=-1; 25 | do { 26 | i++; // i th Players playing 27 | if(i >= entities.getPlayers().size()){ 28 | i=0; 29 | } 30 | StringBuilder str = new StringBuilder(); // To print output 31 | String playeName = entities.getPlayers().get(i); 32 | str.append(playeName); 33 | int diceNumber = dice.getNumberOfDice(); 34 | int endPosition = playerLatestPosition.get(playeName) + diceNumber; 35 | String sl=""; 36 | if(checkFordiceNumberGreaterThan100(endPosition)) { 37 | str.append(" rolled a ").append(diceNumber); 38 | str.append(" and moved from ").append(playerLatestPosition.get(playeName)); 39 | if(entities.getSnakes().get(endPosition)!=null){ 40 | // Captures snake 41 | sl = " after Snake dinner" ; 42 | playerLatestPosition.put(playeName,entities.getSnakes().get(endPosition)); 43 | }else{ 44 | if(entities.getLadders().get(endPosition)!=null){ 45 | // up ladder 46 | sl = " after Ladder ride "; 47 | playerLatestPosition.put(playeName,entities.getLadders().get(endPosition)); 48 | }else{ 49 | playerLatestPosition.put(playeName,endPosition); 50 | } 51 | } 52 | str.append(" to ").append(playerLatestPosition.get(playeName)); 53 | str.append(sl); 54 | } 55 | System.out.println(str); 56 | } while (!isPlayerWon(entities.getPlayers().get(i))); 57 | 58 | return entities.getPlayers().get(i); 59 | } 60 | private boolean isPlayerWon(String player){ 61 | return playerLatestPosition.get(player) == 100; 62 | } 63 | private boolean checkFordiceNumberGreaterThan100(int endPostion){ 64 | return endPostion<=100; 65 | } 66 | 67 | private void initilizePlayersStartValue(){ 68 | for(int i=0;i ladders = new HashMap<>(); 15 | ladders.put(1,7); 16 | ladders.put(5,20); 17 | ladders.put(30,50); 18 | ladders.put(60,80); 19 | HashMap snakes = new HashMap<>(); 20 | snakes.put(10,1); 21 | snakes.put(25,3); 22 | snakes.put(34,7); 23 | snakes.put(78,2); 24 | Player player = new Player(1, "player"); 25 | List players = Collections.singletonList(player); 26 | Game game = new Game(ladders,snakes,players); 27 | SnakeLadderService snakeLadderService = new SnakeLadderService(game); 28 | System.out.println(snakeLadderService.findOptimalPath()); 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /src/com/lavakumar/snakeandladderoptimal/model/Game.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.snakeandladderoptimal.model; 2 | 3 | import java.util.HashMap; 4 | import java.util.List; 5 | 6 | public class Game { 7 | HashMap ladders; 8 | HashMap snakes; 9 | List players; 10 | 11 | public Game(HashMap ladders, HashMap snakes, List players){ 12 | this.ladders = ladders; 13 | this.snakes = snakes; 14 | this.players = players; 15 | } 16 | 17 | public HashMap getLadders() { 18 | return ladders; 19 | } 20 | 21 | public HashMap getSnakes() { 22 | return snakes; 23 | } 24 | 25 | public List getPlayers() { 26 | return players; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/com/lavakumar/snakeandladderoptimal/model/Player.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.snakeandladderoptimal.model; 2 | 3 | public class Player implements Cloneable { 4 | int playerId; 5 | String playerName; 6 | boolean isWin; 7 | Integer playerPosition; 8 | Integer totalMoves; 9 | 10 | public Player(int playerId, String playerName) { 11 | this.playerId = playerId; 12 | this.playerName = playerName; 13 | this.isWin = false; 14 | this.playerPosition = 0; 15 | this.totalMoves = 0; 16 | } 17 | 18 | public int getPlayerId() { 19 | return playerId; 20 | } 21 | 22 | public String getPlayerName() { 23 | return playerName; 24 | } 25 | 26 | public boolean isWin() { 27 | return isWin; 28 | } 29 | 30 | public void setWin(boolean win) { 31 | isWin = win; 32 | } 33 | 34 | public Integer getPlayerPosition() { 35 | return playerPosition; 36 | } 37 | 38 | public void setPlayerPosition(Integer playerPosition) { 39 | this.playerPosition = playerPosition; 40 | } 41 | 42 | public Integer getTotalMoves() { 43 | return totalMoves; 44 | } 45 | 46 | public void setTotalMoves(Integer totalMoves) { 47 | this.totalMoves = totalMoves; 48 | } 49 | 50 | 51 | @Override 52 | public Player clone() { 53 | try { 54 | Player clone = (Player) super.clone(); 55 | // TODO: copy mutable state here, so the clone can't change the internals of the original 56 | return clone; 57 | } catch (CloneNotSupportedException e) { 58 | throw new AssertionError(); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/com/lavakumar/snakeandladderoptimal/service/SnakeLadderService.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.snakeandladderoptimal.service; 2 | 3 | import com.lavakumar.snakeandladderoptimal.model.Game; 4 | import com.lavakumar.snakeandladderoptimal.model.Player; 5 | 6 | import java.util.LinkedList; 7 | import java.util.Queue; 8 | 9 | public class SnakeLadderService { 10 | Game game; 11 | Queue players; 12 | boolean[] visited = new boolean[100]; 13 | public SnakeLadderService(Game game){ 14 | this.game = game; 15 | players = new LinkedList<>(); 16 | players.addAll(game.getPlayers()); 17 | } 18 | 19 | 20 | public int findOptimalPath(){ 21 | int dice; 22 | while (!players.isEmpty()) { 23 | Player currentPlayer = players.poll(); 24 | for(dice=1;dice<=6;dice++) { 25 | int newPosition = currentPlayer.getPlayerPosition() + dice; 26 | if (!isVisited(newPosition)) { 27 | Player player = currentPlayer.clone(); 28 | // Check Ladder 29 | // Check Snakes 30 | if(game.getLadders().get(newPosition)!=null) 31 | newPosition = game.getLadders().get(newPosition); 32 | else if(game.getSnakes().get(newPosition)!=null) 33 | newPosition = game.getSnakes().get(newPosition); 34 | 35 | player.setPlayerPosition(newPosition); 36 | visited[newPosition-1] = true; 37 | player.setTotalMoves(player.getTotalMoves() + 1); 38 | if (isPlayerWin(player)) { 39 | System.out.println(player.getPlayerName()+" Wins!!"); 40 | return player.getTotalMoves(); 41 | } else { 42 | players.add(player); 43 | } 44 | } 45 | } 46 | } 47 | return 0; 48 | } 49 | 50 | private boolean isVisited(int dice){ 51 | return visited[dice-1]; 52 | } 53 | private boolean isPlayerWin(Player player){ 54 | return player.getPlayerPosition() >=100; 55 | } 56 | 57 | } 58 | 59 | -------------------------------------------------------------------------------- /src/com/lavakumar/splitwise/model/ExpenseType.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.splitwise.model; 2 | 3 | import java.util.HashMap; 4 | 5 | public enum ExpenseType { 6 | EQUAL("EQUAL"), 7 | EXACT ("EXACT"), 8 | PERCENT("PERCENT"); 9 | 10 | private final String expense; 11 | 12 | ExpenseType(String s) { 13 | expense = s; 14 | } 15 | 16 | public String toString() { 17 | return this.expense; 18 | } 19 | 20 | private static final HashMap map = new HashMap<>(values().length, 1); 21 | 22 | static { 23 | for (ExpenseType c : values()) map.put(c.expense, c); 24 | } 25 | 26 | public static ExpenseType of(String name){ 27 | return map.get(name); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/com/lavakumar/splitwise/model/Type.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.splitwise.model; 2 | 3 | import java.util.HashMap; 4 | 5 | public enum Type { 6 | EXPENSE ("EXPENSE"), 7 | SHOW ("SHOW"), 8 | QUIT ("QUIT"); 9 | 10 | private final String name; 11 | 12 | Type(String s) { 13 | name = s; 14 | } 15 | 16 | public String toString() { 17 | return this.name; 18 | } 19 | 20 | private static final HashMap map = new HashMap<>(values().length, 1); 21 | 22 | static { 23 | for (Type c : values()) map.put(c.name, c); 24 | } 25 | 26 | public static Type of(String name){ 27 | return map.get(name); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/com/lavakumar/splitwise/model/User.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.splitwise.model; 2 | 3 | 4 | public class User { 5 | int userId; 6 | String userName; 7 | String email; 8 | String mobileNumber; 9 | 10 | public User(int userId, String userName, String email, String mobileNumber) { 11 | this.userId = userId; 12 | this.userName = userName; 13 | this.email = email; 14 | this.mobileNumber = mobileNumber; 15 | } 16 | 17 | public int getUserId() { 18 | return userId; 19 | } 20 | 21 | public void setUserId(int userId) { 22 | this.userId = userId; 23 | } 24 | 25 | public String getUserName() { 26 | return userName; 27 | } 28 | 29 | public void setUserName(String userName) { 30 | this.userName = userName; 31 | } 32 | 33 | public String getEmail() { 34 | return email; 35 | } 36 | 37 | public void setEmail(String email) { 38 | this.email = email; 39 | } 40 | 41 | public String getMobileNumber() { 42 | return mobileNumber; 43 | } 44 | 45 | public void setMobileNumber(String mobileNumber) { 46 | this.mobileNumber = mobileNumber; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/com/lavakumar/splitwise/model/expense/EqualExpense.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.splitwise.model.expense; 2 | 3 | import com.lavakumar.splitwise.model.User; 4 | import com.lavakumar.splitwise.model.split.EqualSplit; 5 | import com.lavakumar.splitwise.model.split.Split; 6 | 7 | import java.util.List; 8 | 9 | public class EqualExpense extends Expense { 10 | 11 | public EqualExpense(double amount, User expensePaidBy, List splits, ExpenseData expenseData) { 12 | super(amount, expensePaidBy, splits, expenseData); 13 | } 14 | 15 | @Override 16 | public boolean validate() { 17 | for(Split split: getSplits()){ 18 | if(!(split instanceof EqualSplit)) return false; 19 | } 20 | return true; 21 | } 22 | 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/com/lavakumar/splitwise/model/expense/ExactExpense.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.splitwise.model.expense; 2 | 3 | import com.lavakumar.splitwise.model.User; 4 | import com.lavakumar.splitwise.model.split.EqualSplit; 5 | import com.lavakumar.splitwise.model.split.ExactSplit; 6 | import com.lavakumar.splitwise.model.split.Split; 7 | 8 | import java.util.List; 9 | 10 | public class ExactExpense extends Expense { 11 | 12 | public ExactExpense(double amount, User expensePaidBy, List splits, ExpenseData expenseData) { 13 | super(amount, expensePaidBy, splits, expenseData); 14 | } 15 | 16 | @Override 17 | public boolean validate() { 18 | double totalAmount = getAmount(); 19 | double totalSplitAmount = 0; 20 | for(Split split: getSplits()){ 21 | if(!(split instanceof ExactSplit)) return false; 22 | ExactSplit exactSplit = (ExactSplit) split; 23 | totalSplitAmount+=exactSplit.getAmount(); 24 | } 25 | return totalAmount == totalSplitAmount; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/com/lavakumar/splitwise/model/expense/Expense.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.splitwise.model.expense; 2 | 3 | import com.lavakumar.splitwise.model.User; 4 | import com.lavakumar.splitwise.model.split.Split; 5 | 6 | import java.util.List; 7 | import java.util.UUID; 8 | 9 | public abstract class Expense { 10 | private final String id; 11 | private double amount; 12 | private User expensePaidBy; 13 | private List splits; 14 | private ExpenseData expenseData; 15 | 16 | 17 | public Expense(double amount, User expensePaidBy, List splits, ExpenseData expenseData) { 18 | this.id = UUID.randomUUID().toString(); 19 | this.amount = amount; 20 | this.expensePaidBy = expensePaidBy; 21 | this.splits = splits; 22 | this.expenseData = expenseData; 23 | } 24 | 25 | public String getId() { 26 | return id; 27 | } 28 | 29 | public double getAmount() { 30 | return amount; 31 | } 32 | 33 | public void setAmount(double amount) { 34 | this.amount = amount; 35 | } 36 | 37 | public User getExpensePaidBy() { 38 | return expensePaidBy; 39 | } 40 | 41 | public void setExpensePaidBy(User expensePaidBy) { 42 | this.expensePaidBy = expensePaidBy; 43 | } 44 | 45 | public List getSplits() { 46 | return splits; 47 | } 48 | 49 | public void setSplits(List splits) { 50 | this.splits = splits; 51 | } 52 | 53 | public ExpenseData getExpenseData() { 54 | return expenseData; 55 | } 56 | 57 | public void setExpenseData(ExpenseData expenseData) { 58 | this.expenseData = expenseData; 59 | } 60 | 61 | public abstract boolean validate(); 62 | } 63 | -------------------------------------------------------------------------------- /src/com/lavakumar/splitwise/model/expense/ExpenseData.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.splitwise.model.expense; 2 | 3 | public class ExpenseData { 4 | private String name; 5 | 6 | public ExpenseData(String name) { 7 | this.name = name; 8 | } 9 | 10 | public String getName() { 11 | return name; 12 | } 13 | 14 | public void setName(String name) { 15 | this.name = name; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/com/lavakumar/splitwise/model/expense/PercentageExpense.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.splitwise.model.expense; 2 | 3 | import com.lavakumar.splitwise.model.User; 4 | import com.lavakumar.splitwise.model.split.ExactSplit; 5 | import com.lavakumar.splitwise.model.split.PercentSplit; 6 | import com.lavakumar.splitwise.model.split.Split; 7 | 8 | import java.util.List; 9 | 10 | public class PercentageExpense extends Expense { 11 | 12 | public PercentageExpense(double amount, User expensePaidBy, List splits, ExpenseData expenseData) { 13 | super(amount, expensePaidBy, splits, expenseData); 14 | } 15 | 16 | @Override 17 | public boolean validate() { 18 | double totalSplitPercent = 0; 19 | for(Split split: getSplits()){ 20 | if(!(split instanceof PercentSplit)) return false; 21 | PercentSplit percentSplit = (PercentSplit) split; 22 | totalSplitPercent+=percentSplit.getPercent(); 23 | } 24 | return 100 == totalSplitPercent; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/com/lavakumar/splitwise/model/split/EqualSplit.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.splitwise.model.split; 2 | 3 | import com.lavakumar.splitwise.model.User; 4 | import com.lavakumar.splitwise.model.split.Split; 5 | 6 | public class EqualSplit extends Split { 7 | 8 | public EqualSplit(User user) { 9 | super(user); 10 | } 11 | } -------------------------------------------------------------------------------- /src/com/lavakumar/splitwise/model/split/ExactSplit.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.splitwise.model.split; 2 | 3 | import com.lavakumar.splitwise.model.User; 4 | import com.lavakumar.splitwise.model.split.Split; 5 | 6 | public class ExactSplit extends Split { 7 | 8 | public ExactSplit(User user, double amount) { 9 | super(user); 10 | this.amount = amount; 11 | } 12 | } -------------------------------------------------------------------------------- /src/com/lavakumar/splitwise/model/split/PercentSplit.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.splitwise.model.split; 2 | 3 | import com.lavakumar.splitwise.model.User; 4 | import com.lavakumar.splitwise.model.split.Split; 5 | 6 | public class PercentSplit extends Split { 7 | double percent; 8 | public PercentSplit(User user, double percent) { 9 | super(user); 10 | this.percent = percent; 11 | } 12 | 13 | public double getPercent() { 14 | return percent; 15 | } 16 | 17 | public void setPercent(double percent) { 18 | this.percent = percent; 19 | } 20 | } -------------------------------------------------------------------------------- /src/com/lavakumar/splitwise/model/split/Split.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.splitwise.model.split; 2 | 3 | import com.lavakumar.splitwise.model.User; 4 | 5 | public abstract class Split { 6 | private User user; 7 | double amount; 8 | 9 | public Split(User user) { 10 | this.user = user; 11 | } 12 | 13 | public User getUser() { 14 | return user; 15 | } 16 | 17 | public void setUser(User user) { 18 | this.user = user; 19 | } 20 | 21 | public double getAmount() { 22 | return amount; 23 | } 24 | 25 | public void setAmount(double amount) { 26 | this.amount = amount; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/com/lavakumar/splitwise/service/ExpenseService.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.splitwise.service; 2 | 3 | import com.lavakumar.splitwise.model.ExpenseType; 4 | import com.lavakumar.splitwise.model.User; 5 | import com.lavakumar.splitwise.model.expense.*; 6 | import com.lavakumar.splitwise.model.split.PercentSplit; 7 | import com.lavakumar.splitwise.model.split.Split; 8 | 9 | 10 | import java.util.List; 11 | 12 | public class ExpenseService { 13 | 14 | public static Expense createExpense(ExpenseType expenseType, double amount, 15 | User expensePaidBy, List splits, ExpenseData expenseData) { 16 | switch (expenseType) { 17 | case EXACT: 18 | return new ExactExpense(amount, expensePaidBy, splits, expenseData); 19 | case PERCENT: 20 | for (Split split : splits) { 21 | PercentSplit percentSplit = (PercentSplit) split; 22 | split.setAmount((amount*percentSplit.getPercent())/100.0); 23 | } 24 | return new PercentageExpense(amount, expensePaidBy, splits, expenseData); 25 | case EQUAL: 26 | int totalSplits = splits.size(); 27 | double splitAmount = ((double) Math.round(amount*100/totalSplits))/100.0; 28 | for (Split split : splits) { 29 | split.setAmount(splitAmount); 30 | } 31 | return new EqualExpense(amount, expensePaidBy, splits, expenseData); 32 | default: 33 | return null; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/com/lavakumar/splitwise/service/SplitWiseService.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.splitwise.service; 2 | 3 | import com.lavakumar.splitwise.model.ExpenseType; 4 | import com.lavakumar.splitwise.model.expense.ExpenseData; 5 | import com.lavakumar.splitwise.model.split.Split; 6 | import com.lavakumar.splitwise.repository.ExpenseRepository; 7 | 8 | import java.util.List; 9 | 10 | public class SplitWiseService { 11 | ExpenseRepository expenseRepository; 12 | 13 | public SplitWiseService(ExpenseRepository expenseRepository){ 14 | this.expenseRepository = expenseRepository; 15 | } 16 | 17 | public void addExpense(ExpenseType expenseType, double amount, 18 | String expensePaidBy, List splits, ExpenseData expenseData) { 19 | expenseRepository.addExpense(expenseType,amount,expensePaidBy,splits,expenseData); 20 | } 21 | 22 | public void showBalance(String userName) { 23 | List balances = expenseRepository.getBalance(userName); 24 | if (balances.isEmpty()) { 25 | System.out.println("No balances"); 26 | } else { 27 | for(String balance: balances){ 28 | System.out.println(balance); 29 | } 30 | } 31 | } 32 | 33 | public void showBalances(){ 34 | List balances = expenseRepository.getBalances(); 35 | if (balances.isEmpty()) { 36 | System.out.println("No balances"); 37 | } else { 38 | for(String balance: balances){ 39 | System.out.println(balance); 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/com/lavakumar/splitwise/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.splitwise.service; 2 | 3 | import com.lavakumar.splitwise.model.User; 4 | import com.lavakumar.splitwise.repository.ExpenseRepository; 5 | 6 | import java.util.List; 7 | import java.util.Optional; 8 | 9 | public class UserService { 10 | ExpenseRepository expenseRepository; 11 | 12 | public UserService(ExpenseRepository expenseRepository){ 13 | this.expenseRepository = expenseRepository; 14 | } 15 | 16 | public void addUser(User user){ 17 | expenseRepository.addUser(user); 18 | } 19 | public User getUser(String userName){ 20 | return expenseRepository.getUser(userName); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/com/lavakumar/tictactoe/Main.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.tictactoe; 2 | 3 | import com.lavakumar.tictactoe.model.Player; 4 | import com.lavakumar.tictactoe.service.PlayTicTacToe; 5 | 6 | import java.util.ArrayList; 7 | import java.util.Scanner; 8 | 9 | public class Main { 10 | public static void main(String[] args) { 11 | Scanner scan = new Scanner(System.in); 12 | 13 | String player1 = scan.next(); 14 | String player2 = scan.next(); 15 | 16 | ArrayList players =new ArrayList<>(); 17 | players.add(new Player(player1,1,"X")); 18 | players.add(new Player(player2,2,"O")); 19 | 20 | 21 | PlayTicTacToe playTicTacToe = new PlayTicTacToe(players,3); 22 | System.out.println("Win: "+playTicTacToe.PlayGame()); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/com/lavakumar/tictactoe/Main_Another.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.tictactoe; 2 | 3 | 4 | 5 | import com.lavakumar.tictactoe.mode.ConsolePrint; 6 | import com.lavakumar.tictactoe.model.Board; 7 | import com.lavakumar.tictactoe.model.Player; 8 | import com.lavakumar.tictactoe.service.TicTacToeService; 9 | import com.lavakumar.tictactoe.validations.GameValidator; 10 | 11 | import java.util.Arrays; 12 | import java.util.HashMap; 13 | import java.util.List; 14 | import java.util.Scanner; 15 | 16 | public class Main_Another { 17 | public static void main(String[] args) { 18 | Board board = new Board(3); 19 | 20 | Player player1 = new Player("Player1",1,"O"); 21 | Player player2 = new Player("Player2",2,"X"); 22 | List players = Arrays.asList(player1, player2); 23 | HashMap playerCheck = new HashMap<>(); 24 | playerCheck.put(player1.getId(), true); 25 | playerCheck.put(player2.getId(), true); 26 | GameValidator gameValidator = new GameValidator(board, playerCheck); 27 | TicTacToeService ticTacToeService = new TicTacToeService(board, players, gameValidator, new ConsolePrint()); 28 | 29 | while (true) { 30 | System.out.println("Choose Input 1: play 2: Exit"); 31 | 32 | Scanner scanner = new Scanner(System.in); 33 | int option = scanner.nextInt(); 34 | switch (option){ 35 | case 1: 36 | System.out.println("Please Enter Your ID"); 37 | Player player = players.get(scanner.nextInt()-1); 38 | System.out.println("Enter Your Move X and Y"); 39 | ticTacToeService.input(scanner.nextInt(),scanner.nextInt(),player); 40 | break; 41 | case 2: System.exit(0); 42 | break; 43 | default: 44 | System.out.println("Choose 1"); 45 | break; 46 | } 47 | 48 | } 49 | 50 | 51 | } 52 | } -------------------------------------------------------------------------------- /src/com/lavakumar/tictactoe/exceptions/BoardException.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.tictactoe.exceptions; 2 | 3 | public class BoardException extends RuntimeException { 4 | public BoardException(String message){ 5 | super(message); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/com/lavakumar/tictactoe/mode/ConsolePrint.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.tictactoe.mode; 2 | 3 | 4 | import com.lavakumar.tictactoe.model.Board; 5 | 6 | public class ConsolePrint implements Print { 7 | @Override 8 | public void printBoard(Board board) { 9 | for(String[] strs: board.getBoard()){ 10 | for(int j=0;j players; 15 | GameValidator gameValidator; 16 | Print print; 17 | int gameCount = 0; 18 | 19 | 20 | public TicTacToeService(Board board, List players, GameValidator gameValidator, Print print){ 21 | this.board = board; 22 | this.players = players; 23 | this.gameValidator = gameValidator; 24 | this.print = print; 25 | } 26 | 27 | public void input(int x, int y, Player player){ 28 | if(!gameValidator.validateCoordinates(x,y)){ 29 | throw new BoardException("Inputs are Not Valid"); 30 | } 31 | if(!gameValidator.validateIsBoardPositionEmpty(x,y)){ 32 | throw new BoardException("Board point Already Filled"); 33 | } 34 | String symbol = player.getSymbol(); 35 | board.setposition(x,y,symbol); 36 | print.printBoard(board); 37 | if(checkBoard(x,y,symbol)){ 38 | System.out.println(" Player "+player.getPlayerName()+" Wins"); 39 | System.exit(0); 40 | } 41 | gameCount++; 42 | if(checkBoardFill()){ 43 | System.out.println("Game Draw"); 44 | System.exit(0); 45 | } 46 | } 47 | 48 | private boolean checkBoard(int row, int column, String symbol){ 49 | boolean winRow = true, winColm = true, winLeft = true, winRight = true; 50 | for(int i=0;i playerCheck; 12 | public GameValidator(Board board, HashMap playerCheck){ 13 | this.board = board; 14 | this.playerCheck = playerCheck; 15 | } 16 | 17 | public boolean validateCoordinates(int x, int y){ 18 | return x < board.getBoard().length && y=0 && y>=0; 19 | } 20 | 21 | public boolean validateIsBoardPositionEmpty(int x, int y){ 22 | return board.getposition(x,y).equals("_"); 23 | } 24 | 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/com/lavakumar/trello/Main.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.trello; 2 | 3 | 4 | 5 | import com.lavakumar.trello.model.BList; 6 | import com.lavakumar.trello.model.Card; 7 | import com.lavakumar.trello.model.User; 8 | import com.lavakumar.trello.service.BoardService; 9 | import com.lavakumar.trello.service.impl.BoardServcieImpl; 10 | 11 | import java.util.ArrayList; 12 | import java.util.Arrays; 13 | import java.util.List; 14 | import java.util.UUID; 15 | 16 | public class Main { 17 | public static void main(String[] args) { 18 | // Input Sample Users 19 | User user1 = new User("u1","u1@gmail.com"); 20 | User user2 = new User( "u2","u2@gmail.com"); 21 | User user3 = new User( "u3","u3@gmail.com"); 22 | User user4 = new User( "u4","u4@gmail.com"); 23 | 24 | List users = new ArrayList<>(Arrays.asList(user1,user2,user3,user4)); 25 | 26 | 27 | // Cards 28 | Card card1 = new Card("Production","Smooth Release"); 29 | card1.setAssignedUser(user1); 30 | Card card2 = new Card("Feature Complete","On Time"); 31 | 32 | Card card3 = new Card("Performance","Need to optimize"); 33 | card3.setAssignedUser(user2); 34 | 35 | // Lists 36 | BList bList1 = new BList("What went well"); 37 | bList1.setCards(Arrays.asList(card1,card2)); 38 | 39 | BList bList2 = new BList("What can be Improved Items"); 40 | 41 | BList bList3 = new BList("Action Items"); 42 | bList3.setCards(Arrays.asList(card3)); 43 | 44 | 45 | 46 | 47 | BoardService boardServcie = new BoardServcieImpl(); 48 | UUID id =boardServcie.createBoard("Sprint Retro"); 49 | // Adding List to Board 50 | boardServcie.addListToBoard(id,bList1); 51 | boardServcie.addListToBoard(id,bList2); 52 | boardServcie.addListToBoard(id,bList3); 53 | 54 | // Adding users to Board 55 | boardServcie.addUsersToBoard(id,users); 56 | 57 | // Print Board 58 | boardServcie.getBoard(id); 59 | 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/com/lavakumar/trello/model/BList.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.trello.model; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.UUID; 6 | 7 | public class BList { 8 | UUID id; 9 | String name; 10 | List cards; 11 | 12 | public BList(String name) { 13 | this.id = UUID.randomUUID(); 14 | this.name = name; 15 | this.cards = new ArrayList<>(); 16 | } 17 | 18 | public UUID getId() { 19 | return id; 20 | } 21 | 22 | public String getName() { 23 | return name; 24 | } 25 | 26 | public void setName(String name) { 27 | this.name = name; 28 | } 29 | 30 | public List getCards() { 31 | return cards; 32 | } 33 | 34 | public void setCards(List cards) { 35 | this.cards = cards; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/com/lavakumar/trello/model/Board.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.trello.model; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.UUID; 6 | 7 | public class Board { 8 | UUID id; 9 | String name; 10 | PRIVACY privacy; 11 | String url; 12 | List users; 13 | List lists; 14 | 15 | public Board(String name) { 16 | this.id = UUID.randomUUID(); 17 | this.name = name; 18 | this.url = "boards/"+this.id; 19 | this.privacy = PRIVACY.PUBLIC; 20 | this.users = new ArrayList<>(); 21 | this.lists = new ArrayList<>(); 22 | } 23 | 24 | public UUID getId() { 25 | return id; 26 | } 27 | 28 | public String getName() { 29 | return name; 30 | } 31 | 32 | public void setName(String name) { 33 | this.name = name; 34 | } 35 | 36 | public PRIVACY getPrivacy() { 37 | return privacy; 38 | } 39 | 40 | public void setPrivacy(PRIVACY privacy) { 41 | this.privacy = privacy; 42 | } 43 | 44 | public String getUrl() { 45 | return url; 46 | } 47 | 48 | public void setUrl(String url) { 49 | this.url = url; 50 | } 51 | 52 | public List getUsers() { 53 | return users; 54 | } 55 | 56 | public void setUsers(List users) { 57 | this.users = users; 58 | } 59 | 60 | public List getLists() { 61 | return lists; 62 | } 63 | 64 | public void setLists(List lists) { 65 | this.lists = lists; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/com/lavakumar/trello/model/Card.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.trello.model; 2 | 3 | import java.util.UUID; 4 | 5 | public class Card { 6 | UUID id; 7 | String name; 8 | String description; 9 | User assignedUser; 10 | 11 | public Card(String name,String description) { 12 | this.id = UUID.randomUUID(); 13 | this.name = name; 14 | this.description = description; 15 | this.assignedUser = null; 16 | } 17 | 18 | public UUID getId() { 19 | return id; 20 | } 21 | 22 | public void setId(UUID id) { 23 | this.id = id; 24 | } 25 | 26 | public String getName() { 27 | return name; 28 | } 29 | 30 | public void setName(String name) { 31 | this.name = name; 32 | } 33 | 34 | public String getDescription() { 35 | return description; 36 | } 37 | 38 | public void setDescription(String description) { 39 | this.description = description; 40 | } 41 | 42 | public User getAssignedUser() { 43 | return assignedUser; 44 | } 45 | 46 | public void setAssignedUser(User assignedUser) { 47 | this.assignedUser = assignedUser; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/com/lavakumar/trello/model/PRIVACY.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.trello.model; 2 | 3 | import java.util.HashMap; 4 | 5 | public enum PRIVACY { 6 | PUBLIC("PUBLIC"), 7 | PRIVATE ("PRIVATE"); 8 | 9 | private final String privacy; 10 | 11 | PRIVACY(String s) { 12 | privacy = s; 13 | } 14 | 15 | public String toString() { 16 | return this.privacy; 17 | } 18 | 19 | private static final HashMap map = new HashMap<>(values().length, 1); 20 | 21 | static { 22 | for (PRIVACY c : values()) map.put(c.privacy, c); 23 | } 24 | 25 | public static PRIVACY of(String name){ 26 | return map.get(name); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/com/lavakumar/trello/model/User.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.trello.model; 2 | 3 | 4 | import java.util.UUID; 5 | 6 | public class User { 7 | UUID userId; 8 | String userName; 9 | String email; 10 | 11 | public User(String userName, String email) { 12 | this.userId = UUID.randomUUID(); 13 | this.userName = userName; 14 | this.email = email; 15 | } 16 | 17 | public UUID getUserId() { 18 | return userId; 19 | } 20 | 21 | 22 | public String getUserName() { 23 | return userName; 24 | } 25 | 26 | public void setUserName(String userName) { 27 | this.userName = userName; 28 | } 29 | 30 | public String getEmail() { 31 | return email; 32 | } 33 | 34 | public void setEmail(String email) { 35 | this.email = email; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/com/lavakumar/trello/service/BListService.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.trello.service; 2 | 3 | 4 | import com.lavakumar.trello.model.Card; 5 | 6 | import java.util.UUID; 7 | 8 | public interface BListService { 9 | void createList(String name); 10 | void deleteList(UUID listId) throws Exception; 11 | void addCardToList(UUID listId, Card card); 12 | } 13 | -------------------------------------------------------------------------------- /src/com/lavakumar/trello/service/BoardService.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.trello.service; 2 | 3 | import com.lavakumar.trello.model.BList; 4 | import com.lavakumar.trello.model.User; 5 | 6 | import java.util.List; 7 | import java.util.UUID; 8 | 9 | public interface BoardService { 10 | UUID createBoard(String name); 11 | void deleteBoard(UUID boardId) throws Exception; 12 | void addUsersToBoard(UUID boardId, List users); 13 | void addUserToBoard(UUID boardId, User user); 14 | void addListToBoard(UUID boardId, BList bList); 15 | 16 | void getBoard(UUID boardId); 17 | } 18 | -------------------------------------------------------------------------------- /src/com/lavakumar/trello/service/CardService.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.trello.service; 2 | 3 | import com.lavakumar.trello.model.User; 4 | 5 | import java.util.UUID; 6 | 7 | public interface CardService { 8 | void createCard(String name,String description); 9 | void deleteCard(UUID cardId) throws Exception; 10 | void assignCardTOUser(UUID cardId, User user); 11 | } 12 | -------------------------------------------------------------------------------- /src/com/lavakumar/trello/service/impl/BListServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.trello.service.impl; 2 | 3 | import com.lavakumar.trello.model.BList; 4 | import com.lavakumar.trello.model.Board; 5 | import com.lavakumar.trello.model.Card; 6 | import com.lavakumar.trello.service.BListService; 7 | 8 | import java.util.HashMap; 9 | import java.util.List; 10 | import java.util.UUID; 11 | 12 | public class BListServiceImpl implements BListService { 13 | HashMap bLists; 14 | public BListServiceImpl(){ 15 | bLists = new HashMap<>(); 16 | } 17 | @Override 18 | public void createList(String name) { 19 | BList list = new BList(name); 20 | this.bLists.put(list.getId(),list); 21 | } 22 | 23 | @Override 24 | public void deleteList(UUID listId) throws Exception { 25 | if(bLists.get(listId)!=null) bLists.remove(listId); 26 | else throw new Exception("ListId "+listId+" Not preset in Lists of Board"); 27 | } 28 | 29 | 30 | @Override 31 | public void addCardToList(UUID listId, Card card) { 32 | BList bList = bLists.get(listId); 33 | if(bList!=null){ 34 | List cards = bList.getCards(); 35 | cards.add(card); 36 | bList.setCards(cards); 37 | } 38 | bLists.put(listId,bList); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/com/lavakumar/trello/service/impl/CardServcieImpl.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.trello.service.impl; 2 | 3 | import com.lavakumar.trello.model.Card; 4 | import com.lavakumar.trello.model.User; 5 | import com.lavakumar.trello.service.CardService; 6 | 7 | import java.util.HashMap; 8 | import java.util.UUID; 9 | 10 | public class CardServcieImpl implements CardService { 11 | HashMap listOfCards; 12 | public CardServcieImpl(){ 13 | listOfCards = new HashMap<>(); 14 | } 15 | @Override 16 | public void createCard(String name,String description) { 17 | Card card = new Card(name,description); 18 | this.listOfCards.put(card.getId(),card); 19 | } 20 | 21 | @Override 22 | public void deleteCard(UUID cardId) throws Exception { 23 | if(listOfCards.get(cardId)!=null) listOfCards.remove(cardId); 24 | else throw new Exception("Card "+cardId+" Not preset in List of Cards"); 25 | } 26 | 27 | @Override 28 | public void assignCardTOUser(UUID cardId, User user) { 29 | Card card = listOfCards.get(cardId); 30 | if(card!=null){ 31 | card.setAssignedUser(user); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/com/lavakumar/uber_rider_flow/ProblemStatement.md: -------------------------------------------------------------------------------- 1 | # 🛺 Cab Booking System – Machine Coding + LLD 2 | 3 | ## Goal 4 | 5 | Design an **Uber-like system** that supports both **Rider Flow** and **Driver Flow** with realistic behaviors such as OTP verification, surge pricing, and cab assignment. The system should be: 6 | 7 | - Extensible 8 | - Object-oriented 9 | - Runnable with sample simulation (console or UI) 10 | - Aligned with real-world interactions (OTP, surge, cab types) 11 | 12 | --- 13 | 14 | ## Core Functionalities 15 | 16 | ### Rider Flow 17 | 1. Rider registers and sets current location 18 | 2. Rider selects destination 19 | 3. System displays available vehicle types with estimated fares (based on distance + vehicle type) 20 | 4. Rider chooses vehicle type and books 21 | 5. OTP is generated and shown to the rider 22 | 6. Rider shares OTP with driver to start the ride 23 | 24 | ### Driver Flow 25 | 1. Drivers register and link to a cab 26 | 2. When a rider books, all nearby available drivers of selected type are notified 27 | 3. First driver to accept gets the booking 28 | 4. Driver enters OTP to start ride 29 | 5. Only driver can end the ride 30 | 31 | --- 32 | 33 | ## System Requirements 34 | 35 | ### Business Rules 36 | - OTP verification required to start the ride (max 3 attempts) 37 | - Cab availability should be based on: 38 | - Vehicle type 39 | - Distance threshold (e.g., 5km) 40 | - Fare calculation depends on: 41 | - Base rate per vehicle type 42 | - Surge pricing multiplier (based on demand) 43 | 44 | 45 | Rider -> id, name, currentLocation 46 | Location -> from , to 47 | Cab -> id, driverName, location, isAvailable, vehicleType 48 | vehicleType -> SEDAN, GO, AUTO, BIKE 49 | Booking - id, Rider, Cab , pickupLocation, destinationLocation, bookingTime, fare, status -------------------------------------------------------------------------------- /src/com/lavakumar/uber_rider_flow/model/Booking.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.uber_rider_flow.model; 2 | 3 | import com.lavakumar.uber_rider_flow.strategy.PricingStrategy; 4 | 5 | import java.time.LocalDateTime; 6 | 7 | public class Booking { 8 | private final Rider rider; 9 | private final Cab cab; 10 | private final Location pickupLocation; 11 | private final Location destination; 12 | private final LocalDateTime bookingTime; 13 | 14 | private LocalDateTime rideStartTime; 15 | 16 | private LocalDateTime rideEndTime; 17 | private double fare; 18 | 19 | private BookingStatus status; 20 | 21 | public Booking(Rider rider, Cab cab, Location destination, PricingStrategy strategy) { 22 | this.rider = rider; 23 | this.cab = cab; 24 | this.pickupLocation = rider.getCurrentLocation(); 25 | this.destination = destination; 26 | this.bookingTime = LocalDateTime.now(); 27 | this.fare = strategy.calculateFare(pickupLocation, destination, cab.getVehicleType()); 28 | } 29 | 30 | public void printSummary() { 31 | System.out.println("✅ Booking Confirmed!"); 32 | System.out.println("Rider: " + rider.getName()); 33 | System.out.println("Driver: " + cab.getDriverName()); 34 | System.out.println("Pickup: " + pickupLocation + " → Drop: " + destination); 35 | System.out.println("Vehicle: " + cab.getVehicleType()); 36 | System.out.println("Fare: ₹" + fare); 37 | System.out.println("Time: " + bookingTime); 38 | } 39 | 40 | public BookingStatus getStatus() { 41 | return status; 42 | } 43 | 44 | public void setStatus(BookingStatus status) { 45 | this.status = status; 46 | } 47 | 48 | public Rider getRider() { 49 | return rider; 50 | } 51 | 52 | public Cab getCab() { 53 | return cab; 54 | } 55 | 56 | public Location getPickupLocation() { 57 | return pickupLocation; 58 | } 59 | 60 | public Location getDestination() { 61 | return destination; 62 | } 63 | 64 | public LocalDateTime getBookingTime() { 65 | return bookingTime; 66 | } 67 | 68 | public double getFare() { 69 | return fare; 70 | } 71 | 72 | public void setFare(double fare) { 73 | this.fare = fare; 74 | } 75 | 76 | public LocalDateTime getRideStartTime() { 77 | return rideStartTime; 78 | } 79 | 80 | public void setRideStartTime(LocalDateTime rideStartTime) { 81 | this.rideStartTime = rideStartTime; 82 | } 83 | 84 | public LocalDateTime getRideEndTime() { 85 | return rideEndTime; 86 | } 87 | 88 | public void setRideEndTime(LocalDateTime rideEndTime) { 89 | this.rideEndTime = rideEndTime; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/com/lavakumar/uber_rider_flow/model/BookingStatus.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.uber_rider_flow.model; 2 | 3 | public enum BookingStatus { 4 | CREATED, 5 | STARTED, 6 | ENDED 7 | } -------------------------------------------------------------------------------- /src/com/lavakumar/uber_rider_flow/model/Cab.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.uber_rider_flow.model; 2 | 3 | public class Cab { 4 | private final String id; 5 | private final String driverName; 6 | private Location location; 7 | private boolean isAvailable; 8 | private VehicleType vehicleType; 9 | 10 | public Cab(String id, String driverName, Location location, VehicleType vehicleType) { 11 | this.id = id; 12 | this.driverName = driverName; 13 | this.location = location; 14 | this.vehicleType = vehicleType; 15 | this.isAvailable = true; 16 | } 17 | 18 | public boolean isAvailable() { 19 | return isAvailable; 20 | } 21 | 22 | public void assignToRide() { 23 | this.isAvailable = false; 24 | } 25 | 26 | public void setLocation(Location location) { 27 | this.location = location; 28 | } 29 | 30 | public Location getLocation() { 31 | return location; 32 | } 33 | 34 | public String getId() { 35 | return id; 36 | } 37 | 38 | public String getDriverName() { 39 | return driverName; 40 | } 41 | 42 | public VehicleType getVehicleType() { 43 | return vehicleType; 44 | } 45 | } -------------------------------------------------------------------------------- /src/com/lavakumar/uber_rider_flow/model/Location.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.uber_rider_flow.model; 2 | public class Location { 3 | private final double x; 4 | private final double y; 5 | 6 | public Location(double x, double y) { 7 | this.x = x; 8 | this.y = y; 9 | } 10 | 11 | public double distanceTo(Location other) { 12 | double dx = this.x - other.x; 13 | double dy = this.y - other.y; 14 | return Math.sqrt(dx * dx + dy * dy); 15 | } 16 | 17 | @Override 18 | public String toString() { 19 | return "(" + x + "," + y + ")"; 20 | } 21 | 22 | // Getters 23 | public double getX() { return x; } 24 | public double getY() { return y; } 25 | } 26 | -------------------------------------------------------------------------------- /src/com/lavakumar/uber_rider_flow/model/Rider.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.uber_rider_flow.model; 2 | 3 | public class Rider { 4 | private final String id; 5 | private final String name; 6 | private Location currentLocation; 7 | 8 | public Rider(String id, String name) { 9 | this.id = id; 10 | this.name = name; 11 | } 12 | 13 | public void updateLocation(Location location) { 14 | this.currentLocation = location; 15 | } 16 | 17 | public Location getCurrentLocation() { 18 | return currentLocation; 19 | } 20 | 21 | public String getName() { 22 | return name; 23 | } 24 | 25 | public String getId() { 26 | return id; 27 | } 28 | } -------------------------------------------------------------------------------- /src/com/lavakumar/uber_rider_flow/model/VehicleFareEstimate.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.uber_rider_flow.model; 2 | 3 | public class VehicleFareEstimate { 4 | private final VehicleType vehicleType; 5 | private final double estimatedFare; 6 | 7 | public VehicleFareEstimate(VehicleType vehicleType, double estimatedFare) { 8 | this.vehicleType = vehicleType; 9 | this.estimatedFare = estimatedFare; 10 | } 11 | 12 | @Override 13 | public String toString() { 14 | return vehicleType + " → ₹" + estimatedFare; 15 | } 16 | } -------------------------------------------------------------------------------- /src/com/lavakumar/uber_rider_flow/model/VehicleType.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.uber_rider_flow.model; 2 | 3 | public enum VehicleType { 4 | HATCHBACK, 5 | SEDAN, 6 | SUV 7 | } 8 | -------------------------------------------------------------------------------- /src/com/lavakumar/uber_rider_flow/service/BookingService.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.uber_rider_flow.service; 2 | 3 | import com.lavakumar.uber_rider_flow.model.Booking; 4 | import com.lavakumar.uber_rider_flow.model.BookingStatus; 5 | import com.lavakumar.uber_rider_flow.model.Cab; 6 | import com.lavakumar.uber_rider_flow.model.Location; 7 | import com.lavakumar.uber_rider_flow.model.Rider; 8 | import com.lavakumar.uber_rider_flow.model.VehicleFareEstimate; 9 | import com.lavakumar.uber_rider_flow.model.VehicleType; 10 | import com.lavakumar.uber_rider_flow.strategy.PricingStrategy; 11 | 12 | import java.math.BigDecimal; 13 | import java.math.RoundingMode; 14 | import java.time.LocalDateTime; 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | 18 | public class BookingService { 19 | private final CabService cabService; 20 | private final PricingStrategy pricingStrategy; 21 | 22 | public BookingService(CabService cabService, PricingStrategy pricingStrategy) { 23 | this.cabService = cabService; 24 | this.pricingStrategy = pricingStrategy; 25 | } 26 | 27 | public List showAvailableVehicleTypes(Location from, Location to) { 28 | List estimates = new ArrayList<>(); 29 | for (VehicleType type : VehicleType.values()) { 30 | double fare = pricingStrategy.calculateFare(from, to, type); 31 | double roundedFare = BigDecimal.valueOf(fare) 32 | .setScale(2, RoundingMode.HALF_UP) 33 | .doubleValue(); 34 | estimates.add(new VehicleFareEstimate(type, roundedFare)); 35 | } 36 | return estimates; 37 | } 38 | 39 | public Booking bookCab(Rider rider, VehicleType vehicleType, Location destination) { 40 | Cab cab = cabService.findNearestAvailableCab(rider.getCurrentLocation(), vehicleType); 41 | if (cab == null) throw new RuntimeException("No available cab of type " + vehicleType); 42 | cab.assignToRide(); 43 | Booking booking = new Booking(rider, cab, destination, pricingStrategy); 44 | booking.setStatus(BookingStatus.CREATED); 45 | return booking; 46 | } 47 | 48 | public void startRide(Booking booking) { 49 | booking.setStatus(BookingStatus.STARTED); 50 | booking.setRideStartTime(LocalDateTime.now()); 51 | System.out.println("🚕 Ride Started..."); 52 | } 53 | 54 | public void endRide(Booking booking) { 55 | booking.setStatus(BookingStatus.ENDED); 56 | booking.setRideEndTime(LocalDateTime.now()); 57 | double finalFare = pricingStrategy.calculateFare( 58 | booking.getPickupLocation(), 59 | booking.getDestination(), 60 | booking.getCab().getVehicleType() 61 | ); 62 | booking.setFare(finalFare); 63 | System.out.println("🏁 Ride Ended."); 64 | } 65 | } 66 | 67 | -------------------------------------------------------------------------------- /src/com/lavakumar/uber_rider_flow/service/CabService.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.uber_rider_flow.service; 2 | 3 | import com.lavakumar.uber_rider_flow.model.Cab; 4 | import com.lavakumar.uber_rider_flow.model.Location; 5 | import com.lavakumar.uber_rider_flow.model.VehicleType; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | public class CabService { 11 | private final List cabs = new ArrayList<>(); 12 | 13 | public void registerCab(String id, String driverName, Location location, VehicleType vehicleType) { 14 | cabs.add(new Cab(id, driverName, location, vehicleType)); 15 | } 16 | 17 | public List findNearbyCabs(Location riderLocation, double maxDistance) { 18 | List nearby = new ArrayList<>(); 19 | for (Cab cab : cabs) { 20 | if (cab.isAvailable() && cab.getLocation().distanceTo(riderLocation) <= maxDistance) { 21 | nearby.add(cab); 22 | } 23 | } 24 | return nearby; 25 | } 26 | 27 | // 🔧 New Method: Find nearest available cab of a given vehicle type 28 | public Cab findNearestAvailableCab(Location riderLocation, VehicleType vehicleType) { 29 | Cab nearestCab = null; 30 | double minDistance = Double.MAX_VALUE; 31 | 32 | for (Cab cab : cabs) { 33 | if (cab.isAvailable() && cab.getVehicleType() == vehicleType) { 34 | double distance = cab.getLocation().distanceTo(riderLocation); 35 | if (distance < minDistance) { 36 | minDistance = distance; 37 | nearestCab = cab; 38 | } 39 | } 40 | } 41 | 42 | return nearestCab; 43 | } 44 | } -------------------------------------------------------------------------------- /src/com/lavakumar/uber_rider_flow/service/RiderService.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.uber_rider_flow.service; 2 | 3 | import com.lavakumar.uber_rider_flow.model.Rider; 4 | 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | public class RiderService { 9 | private final Map riders = new HashMap<>(); 10 | 11 | public Rider registerRider(String id, String name) { 12 | Rider rider = new Rider(id, name); 13 | riders.put(id, rider); 14 | return rider; 15 | } 16 | 17 | public Rider getRider(String id) { 18 | return riders.get(id); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/com/lavakumar/uber_rider_flow/strategy/PricingStrategy.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.uber_rider_flow.strategy; 2 | 3 | import com.lavakumar.uber_rider_flow.model.Location; 4 | import com.lavakumar.uber_rider_flow.model.VehicleType; 5 | 6 | public interface PricingStrategy { 7 | double calculateFare(Location from, Location to, VehicleType vehicleType); 8 | } 9 | -------------------------------------------------------------------------------- /src/com/lavakumar/uber_rider_flow/strategy/VehicleTypePricingStrategy.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.uber_rider_flow.strategy; 2 | 3 | import com.lavakumar.uber_rider_flow.model.Location; 4 | import com.lavakumar.uber_rider_flow.model.VehicleType; 5 | 6 | public class VehicleTypePricingStrategy implements PricingStrategy { 7 | @Override 8 | public double calculateFare(Location from, Location to, VehicleType vehicleType) { 9 | double baseRatePerKm; 10 | switch (vehicleType) { 11 | case HATCHBACK -> baseRatePerKm = 8.0; 12 | case SEDAN -> baseRatePerKm = 10.0; 13 | case SUV -> baseRatePerKm = 12.5; 14 | default -> baseRatePerKm = 10.0; 15 | } 16 | double distance = from.distanceTo(to); 17 | return baseRatePerKm * distance; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/com/lavakumar/uber_with_driver_flow/ProblemStatement.md: -------------------------------------------------------------------------------- 1 | # 🛺 Cab Booking System – Machine Coding + LLD 2 | 3 | ## Goal 4 | 5 | Design an **Uber-like system** that supports both **Rider Flow** and **Driver Flow** with realistic behaviors such as OTP verification, surge pricing, and cab assignment. The system should be: 6 | 7 | - Extensible 8 | - Object-oriented 9 | - Runnable with sample simulation (console or UI) 10 | - Aligned with real-world interactions (OTP, surge, cab types) 11 | 12 | --- 13 | 14 | ## Core Functionalities 15 | 16 | ### Rider Flow 17 | 1. Rider registers and sets current location 18 | 2. Rider selects destination 19 | 3. System displays available vehicle types with estimated fares (based on distance + vehicle type) 20 | 4. Rider chooses vehicle type and books 21 | 5. OTP is generated and shown to the rider 22 | 6. Rider shares OTP with driver to start the ride 23 | 24 | ### Driver Flow 25 | 1. Drivers register and link to a cab 26 | 2. When a rider books, all nearby available drivers of selected type are notified 27 | 3. First driver to accept gets the booking 28 | 4. Driver enters OTP to start ride 29 | 5. Only driver can end the ride 30 | 31 | --- 32 | 33 | ## System Requirements 34 | 35 | ### Business Rules 36 | - OTP verification required to start the ride (max 3 attempts) 37 | - Cab availability should be based on: 38 | - Vehicle type 39 | - Distance threshold (e.g., 5km) 40 | - Fare calculation depends on: 41 | - Base rate per vehicle type 42 | - Surge pricing multiplier (based on demand) 43 | 44 | 45 | Rider -> id, name, currentLocation 46 | Location -> from , to 47 | Cab -> id, driverName, location, isAvailable, vehicleType 48 | vehicleType -> SEDAN, GO, AUTO, BIKE 49 | Booking - id, Rider, Cab , pickupLocation, destinationLocation, bookingTime, fare, status -------------------------------------------------------------------------------- /src/com/lavakumar/uber_with_driver_flow/models/Booking.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.uber_with_driver_flow.models; 2 | 3 | import com.lavakumar.uber_with_driver_flow.models.enums.BookingStatus; 4 | import com.lavakumar.uber_with_driver_flow.pricing.PricingStrategy; 5 | 6 | import java.time.LocalDateTime; 7 | 8 | public class Booking { 9 | private Rider rider; 10 | private Cab cab; 11 | private Location pickupLocation; 12 | private Location destination; 13 | private BookingStatus status; 14 | private LocalDateTime startTime; 15 | private LocalDateTime endTime; 16 | private double fare; 17 | private String otp; 18 | 19 | public Booking(Rider rider, Cab cab, Location destination, PricingStrategy strategy) { 20 | this.rider = rider; 21 | this.cab = cab; 22 | this.pickupLocation = rider.getCurrentLocation(); 23 | this.destination = destination; 24 | this.status = BookingStatus.CREATED; 25 | this.otp = generateOtp(); 26 | this.fare = strategy.calculateFare(pickupLocation, destination, cab.getVehicleType()); 27 | } 28 | 29 | private String generateOtp() { 30 | int otp = 1000 + (int)(Math.random() * 9000); 31 | return String.valueOf(otp); 32 | } 33 | 34 | public void setStatus(BookingStatus status) { this.status = status; } 35 | public void setStartTime(LocalDateTime startTime) { this.startTime = startTime; } 36 | public void setEndTime(LocalDateTime endTime) { this.endTime = endTime; } 37 | public void setFare(double fare) { this.fare = fare; } 38 | 39 | public Rider getRider() { return rider; } 40 | public Cab getCab() { return cab; } 41 | public Location getPickupLocation() { return pickupLocation; } 42 | public Location getDestination() { return destination; } 43 | public BookingStatus getStatus() { return status; } 44 | public LocalDateTime getStartTime() { return startTime; } 45 | public LocalDateTime getEndTime() { return endTime; } 46 | public double getFare() { return fare; } 47 | public String getOtp() { return otp; } 48 | 49 | public void printSummary() { 50 | System.out.println("Rider: " + rider.getName()); 51 | System.out.println("Driver: " + cab.getDriverName()); 52 | System.out.println("Car: " + cab.getCarNumber() + " (" + cab.getVehicleType() + ")"); 53 | System.out.println("Pickup: " + pickupLocation + " → Drop: " + destination); 54 | System.out.println("Fare: ₹" + fare); 55 | System.out.println("Start Time: " + startTime); 56 | System.out.println("End Time: " + endTime); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/com/lavakumar/uber_with_driver_flow/models/Cab.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.uber_with_driver_flow.models; 2 | 3 | import com.lavakumar.uber_with_driver_flow.models.enums.VehicleType; 4 | 5 | public class Cab { 6 | private String id; 7 | private String driverName; 8 | private Location location; 9 | private VehicleType vehicleType; 10 | private String carNumber; 11 | private boolean isAvailable; 12 | 13 | public Cab(String id, String driverName, Location location, VehicleType vehicleType, String carNumber) { 14 | this.id = id; 15 | this.driverName = driverName; 16 | this.location = location; 17 | this.vehicleType = vehicleType; 18 | this.carNumber = carNumber; 19 | this.isAvailable = true; 20 | } 21 | 22 | public boolean isAvailable() { return isAvailable; } 23 | public void assignToRide() { this.isAvailable = false; } 24 | public void setLocation(Location location) { this.location = location; } 25 | 26 | public Location getLocation() { return location; } 27 | public String getDriverName() { return driverName; } 28 | public VehicleType getVehicleType() { return vehicleType; } 29 | public String getCarNumber() { return carNumber; } 30 | public String getId() { return id; } 31 | public void markAvailable() { this.isAvailable = true; } 32 | } 33 | -------------------------------------------------------------------------------- /src/com/lavakumar/uber_with_driver_flow/models/Driver.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.uber_with_driver_flow.models; 2 | 3 | public class Driver { 4 | private String id; 5 | private String name; 6 | 7 | public Driver(String id, String name) { 8 | this.id = id; 9 | this.name = name; 10 | } 11 | 12 | public String getId() { 13 | return id; 14 | } 15 | 16 | public String getName() { 17 | return name; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/com/lavakumar/uber_with_driver_flow/models/Location.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.uber_with_driver_flow.models; 2 | 3 | public class Location { 4 | private double x; 5 | private double y; 6 | 7 | public Location(double x, double y) { 8 | this.x = x; 9 | this.y = y; 10 | } 11 | 12 | public double distanceTo(Location other) { 13 | double dx = this.x - other.x; 14 | double dy = this.y - other.y; 15 | return Math.sqrt(dx * dx + dy * dy); 16 | } 17 | 18 | public double getX() { return x; } 19 | public double getY() { return y; } 20 | 21 | @Override 22 | public String toString() { 23 | return "(" + x + "," + y + ")"; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/com/lavakumar/uber_with_driver_flow/models/Rider.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.uber_with_driver_flow.models; 2 | 3 | public class Rider { 4 | private String id; 5 | private String name; 6 | private Location currentLocation; 7 | 8 | public Rider(String id, String name) { 9 | this.id = id; 10 | this.name = name; 11 | } 12 | 13 | public void updateLocation(Location location) { 14 | this.currentLocation = location; 15 | } 16 | 17 | public Location getCurrentLocation() { 18 | return currentLocation; 19 | } 20 | 21 | public String getName() { 22 | return name; 23 | } 24 | 25 | public String getId() { 26 | return id; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/com/lavakumar/uber_with_driver_flow/models/enums/BookingStatus.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.uber_with_driver_flow.models.enums; 2 | 3 | public enum BookingStatus { 4 | CREATED, 5 | STARTED, 6 | ENDED 7 | } 8 | -------------------------------------------------------------------------------- /src/com/lavakumar/uber_with_driver_flow/models/enums/VehicleType.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.uber_with_driver_flow.models.enums; 2 | 3 | public enum VehicleType { 4 | HATCHBACK, 5 | SEDAN, 6 | SUV 7 | } 8 | -------------------------------------------------------------------------------- /src/com/lavakumar/uber_with_driver_flow/pricing/PricingStrategy.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.uber_with_driver_flow.pricing; 2 | 3 | import com.lavakumar.uber_with_driver_flow.models.Location; 4 | import com.lavakumar.uber_with_driver_flow.models.enums.VehicleType; 5 | 6 | public interface PricingStrategy { 7 | double calculateFare(Location from, Location to, VehicleType vehicleType); 8 | } 9 | -------------------------------------------------------------------------------- /src/com/lavakumar/uber_with_driver_flow/pricing/SurgePricingStrategy.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.uber_with_driver_flow.pricing; 2 | 3 | import com.lavakumar.uber_with_driver_flow.models.Location; 4 | import com.lavakumar.uber_with_driver_flow.models.enums.VehicleType; 5 | 6 | public class SurgePricingStrategy implements PricingStrategy { 7 | private final int demandCount; 8 | // private DemandService demandService 9 | 10 | public SurgePricingStrategy(int demandCount) { 11 | this.demandCount = demandCount; 12 | } 13 | 14 | @Override 15 | public double calculateFare(Location from, Location to, VehicleType vehicleType) { 16 | double baseRatePerKm = switch (vehicleType) { 17 | case HATCHBACK -> 8.0; 18 | case SEDAN -> 10.0; 19 | case SUV -> 12.5; 20 | }; 21 | double distance = from.distanceTo(to); 22 | // demandService.getSurgeMultiplier(from, to); 23 | double surgeMultiplier = 1 + (demandCount / 10.0); // e.g., 10+ riders = 2x fare 24 | return baseRatePerKm * distance * surgeMultiplier; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/com/lavakumar/uber_with_driver_flow/pricing/VehicleTypePricingStrategy.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.uber_with_driver_flow.pricing; 2 | 3 | import com.lavakumar.uber_with_driver_flow.models.Location; 4 | import com.lavakumar.uber_with_driver_flow.models.enums.VehicleType; 5 | 6 | public class VehicleTypePricingStrategy implements PricingStrategy { 7 | @Override 8 | public double calculateFare(Location from, Location to, VehicleType vehicleType) { 9 | double baseRatePerKm = switch (vehicleType) { 10 | case HATCHBACK -> 8.0; 11 | case SEDAN -> 10.0; 12 | case SUV -> 12.5; 13 | }; 14 | double distance = from.distanceTo(to); 15 | return baseRatePerKm * distance; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/com/lavakumar/uber_with_driver_flow/service/CabService.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.uber_with_driver_flow.service; 2 | 3 | import com.lavakumar.uber_with_driver_flow.models.Cab; 4 | import com.lavakumar.uber_with_driver_flow.models.Location; 5 | import com.lavakumar.uber_with_driver_flow.models.enums.VehicleType; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | public class CabService { 11 | private final List cabs = new ArrayList<>(); 12 | 13 | public void registerCab(String id, String driverName, Location location, VehicleType vehicleType, String carNumber) { 14 | cabs.add(new Cab(id, driverName, location, vehicleType, carNumber)); 15 | } 16 | 17 | public List findNearbyCabs(Location riderLocation, double maxDistance) { 18 | List nearby = new ArrayList<>(); 19 | for (Cab cab : cabs) { 20 | if (cab.isAvailable() && cab.getLocation().distanceTo(riderLocation) <= maxDistance) { 21 | nearby.add(cab); 22 | } 23 | } 24 | return nearby; 25 | } 26 | 27 | public Cab findNearestAvailableCab(Location riderLocation, VehicleType vehicleType) { 28 | Cab nearestCab = null; 29 | double minDistance = Double.MAX_VALUE; 30 | 31 | for (Cab cab : cabs) { 32 | if (cab.isAvailable() && cab.getVehicleType() == vehicleType) { 33 | double distance = cab.getLocation().distanceTo(riderLocation); 34 | if (distance < minDistance) { 35 | minDistance = distance; 36 | nearestCab = cab; 37 | } 38 | } 39 | } 40 | 41 | return nearestCab; 42 | } 43 | 44 | public List findNearestAvailableCabs(Location riderLocation, VehicleType vehicleType) { 45 | double minDistance = Double.MAX_VALUE; 46 | List nearestCabs = new ArrayList<>(); 47 | for(Cab cab: cabs) { 48 | if(cab.isAvailable() && cab.getVehicleType() == vehicleType) { 49 | double distance = cab.getLocation().distanceTo(riderLocation); 50 | if(distance < minDistance) { 51 | nearestCabs.add(cab); 52 | } 53 | } 54 | } 55 | return nearestCabs; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/com/lavakumar/uber_with_driver_flow/service/DriverService.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.uber_with_driver_flow.service; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import com.lavakumar.uber_with_driver_flow.models.Driver; 7 | import com.lavakumar.uber_with_driver_flow.models.Location; 8 | 9 | public class DriverService { 10 | private Map drivers = new HashMap<>(); 11 | 12 | public Driver registerDriver(String id, String name) { 13 | Driver driver = new Driver(id, name); 14 | drivers.put(id, driver); 15 | return driver; 16 | } 17 | 18 | public Driver getDriver(String id) { 19 | return drivers.get(id); 20 | } 21 | 22 | public void triggerRideAcceptance(String Driver, Double fare, Location dropLocation){ 23 | // Send Notification 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/com/lavakumar/uber_with_driver_flow/service/RiderService.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.uber_with_driver_flow.service; 2 | 3 | import com.lavakumar.uber_with_driver_flow.models.Rider; 4 | 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | public class RiderService { 9 | private Map riders = new HashMap<>(); 10 | 11 | public Rider registerRider(String id, String name) { 12 | Rider rider = new Rider(id, name); 13 | riders.put(id, rider); 14 | return rider; 15 | } 16 | 17 | public Rider getRider(String id) { 18 | return riders.get(id); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/com/lavakumar/uber_with_driver_flow/utils/VehicleFareEstimate.java: -------------------------------------------------------------------------------- 1 | package com.lavakumar.uber_with_driver_flow.utils; 2 | 3 | import com.lavakumar.uber_with_driver_flow.models.enums.VehicleType; 4 | 5 | public class VehicleFareEstimate { 6 | private VehicleType vehicleType; 7 | private double estimatedFare; 8 | 9 | public VehicleFareEstimate(VehicleType vehicleType, double estimatedFare) { 10 | this.vehicleType = vehicleType; 11 | this.estimatedFare = estimatedFare; 12 | } 13 | 14 | @Override 15 | public String toString() { 16 | return vehicleType + " → ₹" + estimatedFare; 17 | } 18 | } 19 | --------------------------------------------------------------------------------