function [n] = num_subahead(lw, k, w_1, w_2)

% num_subahead(lw, k, w_1, w_2)
%
% lw: length of w_1 (or w_2)
% 1/k : uniform spacing
% Finds the number of spots ahead the nearest subproblem is.

% Function needed : numberOfwts

% Keep track of changes beyond the second element of w

% The two w vectors (3rd component onwards) differ, 
%	find the component with max index that changes

max_index = 0;

for i = 0:(lw - 3)

	if (w_1(lw - i) ~=  w_2(lw - i)) 

		max_index = lw - i;
		break

	end
end

if max_index > 0

	alloted_amt = sum(w_1(max_index:lw));

	n = numberOfwts(max_index - 1, k - alloted_amt);
else
	% The two vectors don't differ beyond the second element
	% Hence the previous subproblem is the nearest
	n = 1;
end