Integer coordinates in a two-dimensional plane are assigned letters from a grid g as follows: point (x,y) is assigned g[y%R][x%C], where R and C are the number of rows and columns in g, respectively. The grid g is given as a String[], where each element is a single row, and g[i][j] is the jth character of the ith element (both 0-indexed).
Consider all rays that originate at (0,0) and move outward, crossing integer coordinates where both x and y are greater than or equal to zero.
Each ray spells out an infinite sequence of letters - the letters assigned to each coordinate crossed by the ray, in the order they are crossed.
You are given a list of words.
You must return the number of rays that contain each of the given words.
A ray contains a word if the word is a substring of the infinite letter sequence spelled out by the ray.
Only consider rays that intersect at least one integer coordinate (x,y) such that both 0<=x<=k and 0<=y<=k, where k is given as a parameter.
In the int[] returned, the ith position represents the number of the described rays that contains ith word given in words.
|