In this post we will be solving the HackerRank Largest Permutation problem using the Java programming language, the VSCode IDE and a Windows computer.
You are given an unordered array of `unique integers` incrementing from 1.
You can swap any two elements a limited number of times.
Determine the largest lexicographical value array that can be created
by executing `no more` than the limited number of swaps.
o 1 <= n <= 10^5
o 1 <= k <= 10^9
We are given a list of unique integers incrementing from 1. We can swap two values at a time up to a number `k`. We need to return the largest possible permutation in the list. Continue reading “HackerRank Largest Permutation in Java”
In this post we will try to define some requirements and then solve the problem. I briefly saw this problem and was not able to get all the details. If it does not make much sense you could specify a variant and go on and solve it.
In this problem we are given a list of offer items and cart items.
The cart items are provided in the order the customer put them in the shopping cart.
The offer items are a list of list of items that must be put into the cart in the order specified.
I guess there could be different versions of the requirements,
but in our case,
we need to make sure that all items in all the item lists are placed in the cart in the specified order.
Perhaps it would be more reasonable to get an additional discount if
a set of items are placed in a specified order in the shopping cart,
or better yet,
if each set of items ends in the shopping cart the customer could receive additional offers.
We need to return true if all items are placed in the shopping cart in the specified order;
otherwise we return false.
o 1 <= number of items <= 100
o 0 <= number of offers <= 100
o The string `anything` in the offers indicates
that the correspoinding item in the shopping cart should be ignored.
The requirements call for having two lists available. In one is a set of offers that require all the specified items to be placed (not just be found) into the cart in the order specified by the offer item. Not only that, but all items must be placed in the cart in the order specified by all offers. That is how we will proceed. Continue reading “Fruit Order in Cart in Java”
In this post we will be solving LeetCode 872. Leaf-Similar Trees. As usual, if interested, please visit the LeetCode site and read the current version of the problem to make sure all is well before you start developing code.
Consider all the leaves of a binary tree,
from left to right order,
the values of those leaves form a leaf value sequence.
Two binary trees are considered leaf-similar if their leaf value sequence is the same.
Return true if and only if the two given trees with head nodes root1 and root2 are leaf-similar.
o The number of nodes in each tree will be in the range [1, 200].
o Both of the given trees will have values in the range [0, 200].
o Depth-First Search
o Binary Tree
We are given two binary trees. We need to determine if the sequence of leaf nodes match or not. Seems like an in-order tree traversal problem. We could populate a list with the leaf nodes of the first tree and repeat with the nodes of the second tree. Our answer will be based on the contents of both lists. Continue reading “LeetCode 872. Leaf-Similar Trees in Java”
Good day! I am approaching the end of my workday. My wife is in the kitchen preparing chocolate frosting for a chocolate cake she baked this morning. We were going to have a piece after lunch, but she was busy and did not get to the frosting.
Yesterday evening my wife and I watched the film No Time To Die which is the last James Bond movie with Daniel Craig. I am a 007 fan. Growing up I read all the novels by Ian Fleming who created the James Bond character. I have watched most of the James Bond films on opening night. This time I decided to wait for the film to be streamed from home.
Of course, there were a few books by Ian Fleming but there are much more films. In other words, most of the films are not based on the original books.
The last two films with Daniel Craig are Spectre and No Time To Die. I did not like Spectre at all. In my rankings it was the worst James Bond film at the time. After watching the new release, I can say that I did not like it either. I would rank it a small notch above the previous movie.
I have not much to say about Daniel Craig. As an actor he can help the delivery of the script, but that is it. If the story and script are not good, the film will follow. Daniel Craig has grown too old to play the 007 role. This is why No Time To Die was the last James Bond film for him.
The original character of James Bond was not represented in this film. The film was slow and his feelings were out of character. The movie was about 2.75 hours in length. To be honest, towards the end I was checking my watch to estimate how much of the movie was left.
There is a film named Knives Out with Daniel Craig and one of the Bond girls Ana de Armas. My wife and I have watched that film a few times. The plot and delivery by most actors is right on. The same cannot be said about No Time to Die.
If you are a fan of James Bond as I am, you must watch the film and then make up your own mind. The taste in people regarding films is hard to quantify. Many times we watch a movie highly rated and it turns out to be a disaster. Not too many times have we experienced the opposite.
On a side note, I was not able to finish this post yesterday. Will complete it right now. Continue reading “Values From List of Lists”
Good day software engineers and developers! It is a Thursday morning and seems like it will be a sunny day with highs in the low 70’s F. Like I mentioned in a previous post, the days are getting shorter and cooler. My wife and I decided to walk after the workday is over. We tried it yesterday and by 06:00 PM we were back home. At that time there is daylight and the temperature is much higher than earlier in the day. Continue reading “Minimum Loss”
This past week my wife, our granddaughters and I returned from a holiday trip to Europe. We visited several cities in Italy, Belgium and Amsterdam. We flew commercial airlines to move between large cities. This made me think of airplane routes and filling up the tanks with fuel. For efficiency reasons airplanes do not get refueled on each stop if it can be avoided. Depending on the part of the world you travel to, airplanes have minimum amounts of fuel they must have on board when they takeoff. The amount depends on the distance to the next stop. I know a few things about the subject because I flew for fun private planes for a few years. For personal reasons (wife and family) I decided to stop. Continue reading “Plane Routes”
I have noticed that multiple times in a week I wake up and check my phone for the time and it is 04:47 AM. Given that I live in the Twin Cities of Minneapolis and St. Paul, there is some day light at that time. I recall a few years ago when I would get up around 05:00 AM to walk the dogs.
I do have an alarm set for 05:00 AM 7 days a week. In addition I have set an appointment in my Google calendar for the same time. Today after waking up at 04:47 AM I checked the calendar to see if there was a message or notification set for 15 minutes before (04:45 AM). Both notification and email are set for 05:00 AM. Continue reading “13 to 15 Java Questions”