## java – How do I know if I’m taking too much time to solve a programming problem?

I’m learning Java for a few months, mainly through the Deitel‘s book “Java – How To Program, 10th Edition“, and now I am on the Chapter 7 learning about Arrays and ArrayLists where things started to get harder, so I decided to go back to Ch.4 to solve its questions (that I skipped) and improve my skills.

After 1h30min programming the Q17, I finally solved it and then found myself in the following question: “Am I taking a long time to solve these problems? Am I going around and around with something that could have been solved in a much simpler way?”.

As a beginner, I have no idea if this is a good time or not. I’d like to receive some opinions from experienced programmers and some tips to improve myself more and more.

Here’s the mentioned question:

4.17 (Gas Mileage) Drivers are concerned with the mileage their automobiles get. One driver has kept track of several trips by
recording the miles driven and gallons used for each tankful. Develop
a Java application that will input the miles driven and gallons used
(both as integers) for each trip. The program should calculate and
display the miles per gallon obtained for each trip and print the
combined miles per gallon obtained for all trips up to this point. All
averaging calculations should produce floating-point results. Use
class Scanner and sentinel-controlled repetition to obtain the data
from the user.

## stochastic calculus – Questions on random time change from Oksendal’s SDE textbook  I have two questions related to the random time change introduced in Oksendal’s textbook on SDEs (page 155-156). Specifically, for Lemma 8.5.6., I have no clue as to why we should define $$t_j$$ in terms of $$alpha_t$$ in such a strange way. Perhaps the biggest confusion comes from the chain of identities in the proof of Lemma 8.5.6., it seems that the author used $$sum_j int_{alpha_j}^{alpha_{j+1}} f(s,omega),mathrm{d}B_s = int_0^{alpha_t} f(s,omega),mathrm{d}B_s,$$ but this relation is not that obvious in my mind (perhaps it is linked to the weird way that $$t_j$$ is defined…) My second question concerns a step in the proof of Theorem 8.5.7, in which the author used the relation $$Delta tilde{B}_j = sqrt{c(alpha_j,omega)},Delta{B}_{alpha_j}$$. However, this relation is not clear to me, as from (8.5.13), we should have $$Delta tilde{B}_j = tilde{B}_{j+1} – tilde{B}_j = int_{alpha_j}^{alpha_{j+1}} sqrt{c(s,omega)},mathrm{d}B_s.$$ So for the claimed identity to hold, we need at least that $$alpha_{j+1} – alpha_j$$ to be sufficiently small (say of order $$mathrm{d}t$$). My deepest thanks for any help on these questions.

Posted on

## Getting a non-emergency passport when it won’t arrive in time

From the Department of State web site, a passport can take “up to 18 weeks from the day an application is submitted to the day a new passport is received.” For expedited service, this can take “up to 12 weeks” which is divided up into “6 weeks for processing and up to 6 weeks for mailing times on the front and back end.” Furthermore, it says you can “Pay an extra \$17.56 for 1-2 day delivery for the return of your completed passport.”

It’s unclear how much time this 1-2 day delivery could shave off the 12 week service. Since it says up to 6 weeks mailing time (which is the same as for non-expedited service) but mentions both front and back end components (which I assume could mean it takes some time to move through the internal mailing system before it actually gets sent out) I assume this means that it could shave anywhere from no time at all all the way up to 5 weeks and 5 days from the time. So there does not seem to be any guarantee that a passport can be obtained in under 12 weeks. And if one has a non-refundable airline ticket and their passport arrives even one day late all the money paid for the ticket and any part of the trip could be lost.

Suppose that one needs their (first) passport in 13 or 14 weeks. It would seem that the 12 week window is sufficient, until one goes to make an appointment and finds that no acceptance facility within 50 miles has any appointments until at least 4 weeks from now. Now suddenly it seems impossible to guarantee that one will receive their passport in time even with expedited shipping.

On the other hand, the only faster service seems to be limited to “life or death emergencies” defined by needing a passport “within 72 hours due to a qualifying life or death emergency” or urgent non-emergency travel which also seems to have a 3 business day window and requires proof of travel.

What does one do in such a situation where their travel time is non-emergency and non-urgent, and is sufficiently in advance to be beyond the expedited service time from the current date but is sooner than the expedited window due to the lack of appointments to start the process?

Update: I also looked at some “agencies” near me. They make claims which seem to contradict the “Department of State” suggesting things like you can get your passport in 10 weeks without them, and also have many horrible one-star reviews on how they are a scam, make promises they can’t keep, prey on people in a rush, and can’t do anything more than you can get directly from the government.

Posted on

## java – Daily coding problem: Job scheduler invoking a function after specific time

This is a problem from Daily Coding Problem. I have implemented it in Java.
For a function `f` I have used `Runnable` interface.

Problem:

This problem was asked by Apple.

Implement a job scheduler which takes in a function `f` and an integer `n`, and calls `f` after `n` milliseconds.

Solution:

``````import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

class Ideone {

interface JobScheduler {
void schedule(final Runnable f, int n);
}

static class JobSchedulerImpl implements JobScheduler {
private final AtomicInteger idValue = new AtomicInteger(0);
private final Map<Integer, Thread> jobs = new ConcurrentHashMap<>();

private int getNextId() {
return idValue.incrementAndGet();
}

@Override
public void schedule(final Runnable f, final int n) throws IllegalArgumentException {
if (n < 0) {
throw new IllegalArgumentException("n cannot be nagative");
}
int id = getNextId();
@Override
public void run() {
try {
f.run();
jobs.remove(id);
} catch (InterruptedException e) {
jobs.remove(id);
}
}
};
jobs.put(id, job);
job.start();
}
}

public static void main(String() args) {
JobScheduler jobScheduler = new JobSchedulerImpl();
jobScheduler.schedule(new Runnable() {
@Override
public void run() {
System.out.println("Job1 launched at: " + System.currentTimeMillis());
}
}, 10000);
jobScheduler.schedule(new Runnable() {
@Override
public void run() {
System.out.println("Job2 launched at: " + System.currentTimeMillis());
}
}, 1000);
}
}
$$```$$
``````

Posted on

## database – How to implement notification system based on time that runs in regular intervals

I have a MySQL database with nodeJS server. I want to implement a notification functionality which is as follows. Once a user registers, I want to (inform) send some particular information to the user that runs in fixed time interval. Something like a task management and tracking.
If user A registers at 10am local time, notification must be sent 24 hours after A registers ie (notifications depends upon time that user registers however with a fixed interval). How do I implement this solution. I have looked at jobs in sql and cron jobs in NodeJs however I’m not sure of the approach, any guidance would be appreciated.

P.S. What would be the approach for same problem with mongoDB?

Posted on

## algorithms – Need the type of time complexity and its formula

If the complexity of my problem is $$O(f_n(n))$$ begins at $$n =4$$ and increases in this sequence:

At

$$n = 4$$ the number of operations = $$(n – 2)$$,

$$n = 5$$ the number of operations = $$((n – 2) (n-2)(n-3)/2)$$

$$n = 6$$ the number of operations = $$((n – 2) (n-2)(n-3) (n-3)(n-4)/4))$$

$$n = 7$$ the number of operations = $$((n-2) (n-2)(n-3) (n-3)(n-4)(n-4)(n-5)/8)$$

$$n = 8$$ the number of operations = $$((n-2) (n-2)(n-3) (n-3)(n-4)(n-4)(n-5)(n-5)(n-6)/16 )$$ … etc.

1. How to formulate the $$f_n(n)$$ for all $$n$$?
2. What is the type of its time complexity?
Posted on

## polynomials – What’s the suitable formula of time complexity?

If the complexity of my problem is $$O(f_n(n))$$ begins at $$n =4$$ and increases in this sequence:

At

$$n = 4$$ the number of operations = $$(n – 2)$$,

$$n = 5$$ the number of operations = $$((n – 2) (n-2)(n-3)/2)$$

$$n = 6$$ the number of operations = $$((n – 2) (n-2)(n-3) (n-3)(n-4)/4))$$

$$n = 7$$ the number of operations = $$((n-2) (n-2)(n-3) (n-3)(n-4)(n-4)(n-5)/8)$$

$$n = 8$$ the number of operations = $$((n-2) (n-2)(n-3) (n-3)(n-4)(n-4)(n-5)(n-5)(n-6)/16 )$$ … etc.

1. How to formulate the $$f_n(n)$$ for all $$n$$?
2. What is the type of its time complexity?
Posted on

## Binance: How to check BTC value by USDT at time of arrival after blockchain disabled it

Let’s say that i received an amount of BTC to my Binance wallet like one week ago.

How can i know the value of it By USDT at time of arrival.

Usually, i was check that from blockchain.com directly where i hover by mouse and see the equivalent value by USDT at time of receive.

Posted on