“Know how to solve every problem that has been solved.” “What I cannot create, I do not understand.” — Richard Feynman

Problem database

Problems

Every problem on the site, in one place. Each is tagged by topic, difficulty, and kind, and carries its own deep-dive links. Problems are pulled into course lessons but also stand alone here for mixed practice.

level
kind
topic

91 problems

hardMultiple choice

In a lazy-propagation segment tree, what does a node's lazy tag represent, and what invariant must hold?

hardMultiple choice

You need, for EVERY node of a tree, the sum of distances from that node to all other nodes. A separate DFS from each node is O(n²) and too slow for n = 10⁵. Which technique computes all n answers in O(n)?

hardMultiple choice

CISD keeps single and double excitations from the HF reference. Given Brillouin's theorem, what role do the singles actually play in the CISD ground-state energy?

hardMultiple choice

For TWO non-interacting H₂ molecules, FCI gives exactly 2× one H₂ but CISD gives a higher energy. The missing piece is one specific determinant. Which?

hardMultiple choice

Stretching H₂ toward dissociation makes the correlation problem qualitatively harder than it is at equilibrium. Which kind of correlation dominates there?

hardMultiple choice

UHF rescues the H₂ dissociation curve by letting the α and β electrons take different spatial orbitals. What does it pay for this?

hardMultiple choice

Mulliken charges are famously basis-set sensitive — add diffuse functions and the numbers can change wildly. What is the structural reason?

Go deeper ↓Hartree-Fock Method
hardMultiple choice

For a closed-shell system with two electrons in one spatial orbital φ (opposite spins), the exchange integral between them…

hardMultiple choice

Is the total Hartree-Fock energy equal to the sum of the occupied orbital energies Σεᵢ?

Go deeper ↓Hartree-Fock Method
hardMultiple choice

Restricted Hartree-Fock (RHF) famously fails as H₂ is pulled apart. The reason is that…

Go deeper ↓Hartree-Fock Method
hardMultiple choice

FCI is often called 'exact'. Exact in what sense?

hardMultiple choice

FCI is variational and size-consistent. Which statement about the FCI energy is therefore true?

hardMultiple choice

Koopmans' theorem makes two crude approximations, yet its ionization potentials are often surprisingly decent. Why?

Go deeper ↓Hartree-Fock Method
hardMultiple choice

Møller-Plesset perturbation theory splits the Hamiltonian as H = H₀ + V. What is H₀, and what is the perturbation?

hardMultiple choice

The MP2 energy is a sum of terms |coupling|² / (εᵢ + εⱼ − εₐ − εᵦ). Which systems should make you distrust it?

hardMultiple choice

Two Gaussian primitives have exponents α (large) and β (small) on centres A and B. Their product Gaussian sits at P. Where is P?

hardMultiple choice

The Roothaan-Hall equations take the form FC = SCε (a generalized eigenvalue problem) rather than FC = Cε. The overlap matrix S appears because…

hardMultiple choice

The converged SCF electronic energy is computed as E = ½ tr[P(h + F)] rather than tr[P h]. Why the factor of ½ and the (h + F)?

Go deeper ↓The SCF iteration
hardMultiple choice

Why are the Slater-Condon rules said to 'fall out for free' in second quantization?

hardMultiple choice

A single Slater determinant with one α and one β electron in different spatial orbitals (|φ₁α φ₂β|) is…

hardMultiple choice

For H₂'s σ→σ excited states, the triplet lies below* the singlet by exactly 2K_ov = 0.363 hartree (in STO-3G). What pays for the triplet's discount?

hardMultiple choice

Schwarz screening lets a code skip computing an ERI (ab|cd) when…

hardMultiple choice

The Coulson-Fischer point of H₂ (≈2.1 bohr in this basis) marks the geometry where…

hardMultiple choice

UHF dissociates H₂ to the right energy (two free atoms) with the wrong wavefunction (⟨S²⟩ ≈ 1). For which prediction would this contamination actually bite?

introMultiple choice

A local object is created on the stack inside a function. When does its destructor run?

Go deeper ↓Classes and objects
introMultiple choice

In int x = 5; int& r = x;, which expression below is an lvalue?

Go deeper ↓Pointers in C++
introPredict + reveal

Using the prefix-sum identity sum(l, r) = P[r+1] − P[l], compute sum(2, 4). Work it out from the arrays below before revealing.

a = [3, 1, 4, 1, 5]          # indices 0..4
P = [0, 3, 4, 8, 9, 14]      # P[i] = sum of a[0..i-1]

sum(2, 4) = ?
introMultiple choice

The variational principle says that for any trial wavefunction ψ, the Rayleigh quotient ⟨ψ|H|ψ⟩ / ⟨ψ|ψ⟩ is…

standardPredict + reveal

Does this compile? If not, why? Predict before revealing.

int a = 3, b = 4;
int* p = &(a + b);
std::cout << *p;
Go deeper ↓Pointers in C++
standardPredict + reveal

Three guard objects are constructed in order. What is the destruction order at the closing brace? Predict the full output.

struct Guard {
    const char* name;
    Guard(const char* n) : name(n) { std::cout << "ctor " << name << "\n"; }
    ~Guard()                       { std::cout << "dtor " << name << "\n"; }
};

int main() {
    Guard a("A");
    Guard b("B");
    Guard c("C");
}
Go deeper ↓Classes and objects
standardPredict + reveal

What does this print? Look closely at how n is captured.

int n = 10;
auto f = [n]() { return n + 1; };
n = 100;
std::cout << f();
Go deeper ↓Lambdas in C++
standardMultiple choice

Under the hood, what is a C++ lambda expression?

Go deeper ↓Lambdas in C++
standardMultiple choice

Why prefer std::make_unique<T>(args...) over std::unique_ptr<T>(new T(args...))?

Go deeper ↓Ownership by diff
standardPredict + reveal

What does this print? Pay attention to the state of a after the move.

std::vector<int> a = {1, 2, 3};
std::vector<int> b = std::move(a);
std::cout << b.size() << " " << a.size();
standardShort answer

Name the special member function that constructs a new object by stealing the resources of an expiring one. Two words.

Go deeper ↓Ownership by diff
standardMultiple choice

Why does wrapping a mutex lock in a stack guard (std::lock_guard) make it exception-safe, where a manual lock() / unlock() pair is not?

Go deeper ↓Classes and objects
standardMultiple choice

The Rule of Five says that if you write one of a certain set of special member functions, you should think about all five. Which set?

standardMultiple choice

What does the Rule of Zero recommend, and when does it apply?

Go deeper ↓Ownership by diff
standardPredict + reveal

What does this print? The template parameter is taken by value.

template<class T> void bump(T x) { x += 1; }

int a = 5;
bump(a);
std::cout << a;
standardMultiple choice

Given template<class T> T add(T a, T b) { return a + b; }, you call add(1, 2) and add(1.5, 2.5). How many concrete versions of add does the compiler generate?

standardMultiple choice

What happens here?

auto a = std::make_unique<int>(5);
std::unique_ptr<int> b = a;   // <-- this line
Go deeper ↓Ownership by diff
standardMultiple choice

What does std::move(x) actually do at runtime?

Go deeper ↓Ownership by diff
standardMultiple choice

Bitmask DP for the traveling salesman runs in O(2ⁿ · n²). Under a typical contest budget of about 10⁸ basic operations, what is the largest n that fits comfortably?

standardMultiple choice

In digit DP (building a number left-to-right under an upper bound), the 'tight' flag is true at a position exactly when...

standardMultiple choice

For "maximum sum of a subsequence with no two chosen elements adjacent" (house robber) over an array, what is a sufficient and minimal DP state?

standardMultiple choice

A contestant codes 0/1 knapsack with the state (item index, capacity used, current total value) and gets Memory Limit Exceeded. Which dimension is redundant and causing the blowup?

standardPredict + reveal

A Fenwick query walks i down to 0 by repeatedly subtracting the lowest set bit: i -= i & (-i), summing bit[i] each step. Which indices does query(11) visit? (11 = 1011 in binary.) List them before revealing.

long long query(int i) {
    long long s = 0;
    for (; i > 0; i -= i & -i)
        s += bit[i];
    return s;
}

// query(11): which i values?
standardMultiple choice

For a positive integer i in two's-complement, what does the expression i & (-i) compute?

standardMultiple choice

Which practice habit most efficiently raises your competitive-programming rating over a season?

standardMultiple choice

You must apply many range updates of the form "add v to every a[i] for i in [l, r]" and read the array only once, at the end. Using a difference array d (1-indexed, sized n+1, all zero), what is the correct O(1) action per update?

standardMultiple choice

A problem has n ≤ 2·10⁵ and a 1-second time limit. Which intended time complexity should you assume when designing the solution?

standardMultiple choice

Both a Fenwick tree and a segment tree do point update + range query in O(log n). Which task specifically needs a segment tree, because a plain Fenwick tree cannot do it directly?

standardMultiple choice

A sparse table answers range minimum in O(1) by combining two power-of-two blocks that overlap in the middle. The very same structure does NOT work for range sum. Why?

standardMultiple choice

Your clever solution gets Wrong Answer on a hidden test, somewhere among 10⁵ cases you cannot see. What is the most reliable way to find the failing case?

standardMultiple choice

In a stress-testing harness, why should the random generator be bounded to produce SMALL inputs (e.g. n ≤ 8) rather than full-size ones?

standardMultiple choice

Forty minutes into a contest you have spent all of it on problem B with no working idea, and problems C and D are still unread. What is the best move?

standardNumeric

Rerooting sum-of-distances uses ans[v] = ans[u] + (n − 2·sz[v]) when moving the root from u to an adjacent child v. A tree has n = 6 nodes; the subtree rooted at v has sz[v] = 2; and ans[u] = 9. Compute ans[v].

standardMultiple choice

Why does quantum chemistry build orbitals out of Gaussians rather than the more physically-accurate Slater functions?

standardMultiple choice

The Gaussian product theorem states that the product of two s-type Gaussians centred at A and B is…

standardMultiple choice

In an STO-3G calculation, the three contraction coefficients that combine the primitive Gaussians into one basis function are…

standardMultiple choice

What physical feature of a true atomic orbital is lost when you approximate it with a sum of Gaussians?

standardMultiple choice

The Davidson correction ΔE_Q ≈ (1 − c₀²)(E_CISD − E_HF) estimates the missing quadruples. What does a SMALL c₀ (HF-coefficient) signal?

standardMultiple choice

The density matrix P = 2C_occ C_occᵀ compresses the wavefunction. What does its trace with the overlap matrix, tr(PS), always equal?

Go deeper ↓The SCF iteration
standardMultiple choice

HeH⁺'s dipole moment is 0.889 a.u. with the origin at He. For H₂O the origin never needs stating. What's the difference?

standardMultiple choice

Why is the Hartree product ψ(r₁,r₂) = φ(r₁)φ(r₂) an unacceptable wavefunction for two electrons?

standardMultiple choice

A Slater determinant automatically encodes the Pauli exclusion principle because…

standardMultiple choice

The Slater–Condon rules are useful because they…

standardMultiple choice

What does it mean that Hartree-Fock is a mean-field theory?

Go deeper ↓Hartree-Fock Method
standardMultiple choice

The correlation energy is defined as…

Go deeper ↓Hartree-Fock Method
standardMultiple choice

What is the Full Configuration Interaction (FCI) wavefunction?

standardMultiple choice

Why is FCI limited to small systems (roughly 10–20 electrons in modest bases)?

standardNumeric

H₂ in the 6-31G basis has M = 4 spatial orbitals, one α electron, and one β electron. How many determinants does the FCI expansion contain? (Use N = C(M, Nα) · C(M, Nβ).)

standardMultiple choice

According to Koopmans' theorem, the ionization potential of a molecule is approximately…

Go deeper ↓Hartree-Fock Method
standardMultiple choice

For H₂/STO-3G the MP2 correction is −13.2 mHa, computed from a single excitation. What made the minimal basis collapse the whole MP2 sum to one term?

standardMultiple choice

The Boys function F₀(x) shows up in which integrals when using a Gaussian basis?

standardMultiple choice

Why do the overlap and kinetic-energy integrals between two Gaussians on different centres have simple closed forms?

standardMultiple choice

Diagonalizing the Roothaan-Hall equations in an N-function basis returns N orbitals. The N/2 with the lowest energies are occupied. What are the rest?

standardMultiple choice

In practice, how do you solve the generalized eigenvalue problem FC = SCε for a non-orthogonal Gaussian basis?

standardMultiple choice

Why must Hartree-Fock be solved by iteration (the SCF cycle) rather than in one shot?

Go deeper ↓The SCF iteration
standardMultiple choice

The SCF procedure is best described as…

Go deeper ↓The SCF iteration
standardMultiple choice

A common SCF starting guess is the core Hamiltonian guess. What does it ignore in the first step?

Go deeper ↓The SCF iteration
standardMultiple choice

In second quantization, what does the number operator a_p† a_p return when applied to a determinant?

standardMultiple choice

The anticommutator {a_p†, a_q†} = 0. Setting p = q gives (a_p†)² = 0. Which physical law is this?

standardMultiple choice

⟨S²⟩ for a UHF wavefunction is computed as Ms(Ms+1) + Nβ − Σ|⟨φᵢα|φⱼβ⟩|². When does it reduce to the exact singlet value of 0?

standardMultiple choice

How does the number of two-electron repulsion integrals (ERIs) scale with the number of basis functions N?

standardMultiple choice

Real-orbital ERIs obey an 8-fold permutation symmetry, e.g. (ab|cd) = (ba|cd) = (cd|ab) = …. Practically, this means a code can…

standardMultiple choice

In chemist notation, what does the two-electron integral (ab|cd) represent?

standardMultiple choice

Pople-Nesbet UHF builds two Fock matrices. In Fα, the exchange term subtracts only Pα — never Pβ. Why?

Go deeper ↓Hartree-Fock Method
standardMultiple choice

For hydrogen, the trial orbital ψ(r) = e^{−ζ|r|} with ζ as a parameter makes the variational calculation a…

standardMultiple choice

You compute the energy of a deliberately crude trial wavefunction and get −0.40 Hartree for hydrogen (exact: −0.50). What can you conclude?

standardMultiple choice

Optimizing ζ in the trial ψ = e^{−ζ|r|} for hydrogen gives E = −0.5 hartree — the exact ground-state energy, exactly. Why does the variational method land on the truth here?