From b76ee73dfcfc1d3ffc99990429ad714169626385 Mon Sep 17 00:00:00 2001 From: Mansi Bhandari Date: Mon, 7 Oct 2024 19:54:18 +0530 Subject: [PATCH] new update --- BrowserHistory.class | Bin 0 -> 1465 bytes BrowserHistoryDesignByMansiBhandari.java | 68 +++++++++++++++++++++++ DesignBrowserHistory.class | Bin 0 -> 1528 bytes 3 files changed, 68 insertions(+) create mode 100644 BrowserHistory.class create mode 100644 BrowserHistoryDesignByMansiBhandari.java create mode 100644 DesignBrowserHistory.class diff --git a/BrowserHistory.class b/BrowserHistory.class new file mode 100644 index 0000000000000000000000000000000000000000..6792eca777bcd6baf1000538c203c0454e68525a GIT binary patch literal 1465 zcma)6-*XdH7(F-Hu*v2EA+-^xSOk=8qKy_1Fr~Cqu)(yT!D8WsO>!HSCcDgLQ>=fF zGtT&=jh0qLbqF)4+3Yi?)F0qCXyLsAx#{X zID(@BM{WfEv%U%zdF}_B0_NjgD_4Jwp~I_L97Ep3n8Z66XXxlL$(?pvV7xet+b6JU zKhU)AN*u=t0ofV^f%3wd*H%9Wh?)kTka!QL1dP7>qlyxV+>;Wg@c}aoRL|ew!FaJ| zA0)7F7UxWSDDe@_?@EglEIHw0!u1?7rHZwh9l_cXB@LVGsL;g6BSme5f$McN;*>;1 z!zFvJm&RvQ-c>4W`E51T@_QCjx}bY<@r|U109AV>jn4(Fj_-H6dl6S8uIh-?hTC_; zG^#{hb6TqD`|BDtjcWqgO@9y$no&>&*D+^eUg8E8Mul$nL)D`^UZ#X$Rb0Pvm-<7B zP)@I^Mc$OSg|ArJrqfzKP{CNOg&J;~_*$Z_t1s_l9@6@g5{?RZW&2-vuDZ;aE-zAnZZW?2klf#nrAT6aCQJm@u5aL;LW z={ej8DSyd%8t;vs<9Y&x;=_YL_6qCX@CQLl-EwvC*yxx~>Cxq2W%;teFQFd;1ip=S z4emLpv{Ur4zg+Kew}@nP|8!{^qVx*p>NYaZVU_-XRo+1^f%~Q8a}<8#U4ieo78ng8 z8_01zhLgx+5@S5&48*8Gj5?=bc5qUFM!|UW6DG80&ug@I@IEPi{_h{{+a+9$F2}5i zeXPgHb%IkqflGW@*KrCf)M79Lo6H=Dn7*f5V zEnF_=zlhcuuD@fpY;57nEi4{1m*_3$@5a|sThI=DjplAd&K%mW`!)^96f3YW&CXq5 jA1|_omvJ6f=() history; // List to store URLs of websites visited + private int currentIndex; // Current index in history + + // Constructor to initialize the browser with a homepage + public BrowserHistoryDesgin(String homepage) { + history = new ArrayList<>(); + history.add(homepage); // Add homepage to history + currentIndex = 0; // Set the current page to the homepage + } + + // Method to visit a new URL + public void visit(String url) { + // Remove forward history if any (clear anything beyond currentIndex) + while (history.size() > currentIndex + 1) { + history.remove(history.size() - 1); + } + history.add(url); // Add the new URL to history + currentIndex++; // Move to the new URL in history + } + + // Method to go back in history by 'steps' number of steps + public String back(int steps) { + // Ensure we don't move past the beginning of the history + currentIndex = Math.max(0, currentIndex - steps); + return history.get(currentIndex); + } + + // Method to go forward in history by 'steps' number of steps + public String forward(int steps) { + // Ensure we don't move past the last visited page in history + currentIndex = Math.min(history.size() - 1, currentIndex + steps); + return history.get(currentIndex); + } + + // Main method to test the functionality + public static void main(String[] args) { + BrowserHistory browserHistory = new BrowserHistory("leetcode.com"); // Start at homepage "leetcode.com" + + // Visit new websites + browserHistory.visit("google.com"); // Visit google.com + browserHistory.visit("facebook.com"); // Visit facebook.com + browserHistory.visit("youtube.com"); // Visit youtube.com + + // Move back and forward in history + System.out.println(browserHistory.back(1)); // Go back 1 step to facebook.com + System.out.println(browserHistory.back(1)); // Go back 1 more step to google.com + System.out.println(browserHistory.forward(1)); // Move forward 1 step to facebook.com + + // Visit a new website, which clears forward history + browserHistory.visit("linkedin.com"); // Visit linkedin.com (clears forward history) + + // Attempt to move forward, but it won't work as forward history is cleared + System.out.println(browserHistory.forward(2)); // No forward pages, stay on linkedin.com + System.out.println(browserHistory.back(2)); // Go back 2 steps to google.com + System.out.println(browserHistory.back(7)); // Go back as far as possible to leetcode.com + } +} + diff --git a/DesignBrowserHistory.class b/DesignBrowserHistory.class new file mode 100644 index 0000000000000000000000000000000000000000..b784d12c79d3c0915966a3b851255d93f5479e2f GIT binary patch literal 1528 zcmah}U2_vv7=BK&VUx`kLi(XlpcJg+0~#nFqG`)lg$C1t28)#&Hpxj?n(Wri2B_Em z4zHYH#w&H86`66o_IG&iA8;(s*(@Y&opE;N%sKCQ-{*PWkF$UN``hmT=J1t)2%<|e3fDZ(+E|d^bfp0u z(FBq(bqtxQLHfrWZe;x0wA}iFnV%`#2v%jufiHkia&)s%C)((DBkvnz3&7ciQx+ibmy zxM<>%iikb2JGLLkWui8$nyk9+nnI1^6M^K0+x5HEASi)Z%;}gnaRpa*3ft)TvdwJh zObNX**lyu2_4*Vct#(m~yl&zK7MNYts;w!lrNNSgY7N}PEgg#{N=n{vP_mt19E)`Y z-EtJ_XC}%DRd2Z7Q_HKzv8)PYJ8QCTJ1P}ULWQ$s`CX4aoZ3A|vjcq#Ma&ne@&@b6 zu`1h+T<*53(z|C>TeJ*SeCl7a*2A;bwp16#G7t6wWmj1Eire*S@}{kV5B=AiPpc#` z$z&pYY7wN>n}EQb;B=Q3PAK;=+Sq2UpYybcXyAW5w*`@V4SjVBiI*^PFJR zT=XTzex|R$7hJ~}4J4q!Abt{uVPXP9yyYl_sLc@dqJnva!vfrlX%Bxus%JSSaR2%C zUxO^Gfk#Lc8KB|=Se^vaNnspE`6(71k$;d7!=&JR3}mN>E-9jZdUdV7 zhxFn9lTI?J6Z}D(L>5zh(ovEoa1URGq(6owZM;TuHGO6ag>pVUvxy7&^hd$^G1p&E z%xjytwuw*oZg10?PcMaTu}vt0a^v=GL`v`N`|X}#dqHUitDi!i)jv(KXK)JBm_dR6 X^t0^2IV|(Eit~`{kiZIKI67|t{wqRO literal 0 HcmV?d00001