Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3. import java.util.logging.Logger;
  4. import java.util.logging.Level;
  5.  
  6. /*
  7. * To execute Java, please define "static void main" on a class
  8. * named Solution.
  9. *
  10. * If you need more classes, simply define them inline.
  11. */
  12.  
  13. /*
  14. * An engineer wants to analyze some log data about the pages users visit on Pinterest.
  15. * The logs are stored in a String in the following format:
  16. Timestamp, page type
  17. 2016-06-23 20:48:21, SEARCH
  18. 2016-06-23 20:48:22, PIN
  19. 2016-06-23 20:49:26, BOARD
  20. */
  21.  
  22. class Solution {
  23. // First, write a function that takes in the log string and outputs an array containing the pages the user visited, in order.
  24. public static String[] getPath(String log){
  25. Logger logger = Logger.getLogger(Solution.class.getName());
  26. // TODO: You fill this in!
  27. return new String[0];
  28. // See an example usage / test case in the main method below.
  29. }
  30.  
  31. // 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.
  32. public static String[] getMostCommonPath(String log) {
  33. // TODO: You fill this in!
  34. return new String[3];
  35. // See an example usage / test case in the main method below.
  36. }
  37.  
  38. public static void main(String[] args) {
  39. // Test cases for getPath (feel free to add your own!):
  40. String log = "Timestamp, page type\n" +
  41. "2016-09-23 20:48:21, SEARCH\n" +
  42. "2016-09-23 20:48:22, PIN\n" +
  43. "2016-09-23 20:49:26, BOARD";
  44. System.out.println(Arrays.toString(getPath(log)) + " (should be [SEARCH, PIN, BOARD])");
  45.  
  46. // Test cases for getMostCommonPath (feel free to add your own!):
  47. System.out.println(Arrays.toString(getMostCommonPath(log)) + " (should be [SEARCH, PIN, BOARD])");
  48.  
  49. String longerLog = "Timestamp, page type\n" +
  50. "2019-06-23 20:48:21, PIN\n" +
  51. "2019-06-23 20:48:22, BOARD\n" +
  52. "2019-06-23 20:49:26, PIN\n" +
  53. "2019-06-23 20:50:01, PIN\n" +
  54. "2019-06-23 20:50:03, SEARCH\n" +
  55. "2019-06-23 20:49:24, SEARCH\n" +
  56. "2019-06-23 20:49:24, BOARD\n" +
  57. "2019-06-23 20:49:25, PIN\n" +
  58. "2019-06-23 20:50:31, PIN\n";
  59. System.out.println(Arrays.toString(getMostCommonPath(longerLog)) + " (should be [BOARD, PIN, PIN])");
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement