Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- import java.util.logging.Logger;
- import java.util.logging.Level;
- /*
- * To execute Java, please define "static void main" on a class
- * named Solution.
- *
- * If you need more classes, simply define them inline.
- */
- /*
- * An engineer wants to analyze some log data about the pages users visit on Pinterest.
- * The logs are stored in a String in the following format:
- Timestamp, page type
- 2016-06-23 20:48:21, SEARCH
- 2016-06-23 20:48:22, PIN
- 2016-06-23 20:49:26, BOARD
- */
- class Solution {
- // First, write a function that takes in the log string and outputs an array containing the pages the user visited, in order.
- public static String[] getPath(String log){
- Logger logger = Logger.getLogger(Solution.class.getName());
- // TODO: You fill this in!
- return new String[0];
- // See an example usage / test case in the main method below.
- }
- // Now the engineer wants to analyze the log data. The engineer wants to know what is the most commonly visited sequence of 3 page types. Write a function to find the most-common "path" of three pages.
- public static String[] getMostCommonPath(String log) {
- // TODO: You fill this in!
- return new String[3];
- // See an example usage / test case in the main method below.
- }
- public static void main(String[] args) {
- // Test cases for getPath (feel free to add your own!):
- String log = "Timestamp, page type\n" +
- "2016-09-23 20:48:21, SEARCH\n" +
- "2016-09-23 20:48:22, PIN\n" +
- "2016-09-23 20:49:26, BOARD";
- System.out.println(Arrays.toString(getPath(log)) + " (should be [SEARCH, PIN, BOARD])");
- // Test cases for getMostCommonPath (feel free to add your own!):
- System.out.println(Arrays.toString(getMostCommonPath(log)) + " (should be [SEARCH, PIN, BOARD])");
- String longerLog = "Timestamp, page type\n" +
- "2019-06-23 20:48:21, PIN\n" +
- "2019-06-23 20:48:22, BOARD\n" +
- "2019-06-23 20:49:26, PIN\n" +
- "2019-06-23 20:50:01, PIN\n" +
- "2019-06-23 20:50:03, SEARCH\n" +
- "2019-06-23 20:49:24, SEARCH\n" +
- "2019-06-23 20:49:24, BOARD\n" +
- "2019-06-23 20:49:25, PIN\n" +
- "2019-06-23 20:50:31, PIN\n";
- System.out.println(Arrays.toString(getMostCommonPath(longerLog)) + " (should be [BOARD, PIN, PIN])");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement