Hi there, I've fighting for several days with a problem and I feel stuck. These are the conditions for the task: Word search 1. We have a two-dimensional array that contains lowercase letters. 2. The detectAllWords method must find all the words in the wordSearch array. 3. The element(startX, startY) must correspond to the first letter of the word, while the element(endX, endY) corresponds to the last letter. text is the word itself, located between the start and end elements 4. All the words are in the array. 5. The words can be arranged horizontally, vertically, and diagonally, both forward and backward. 6. The main method is not tested. What I've done; ***********************************************************************************************************
``````package com.codegym.task.task20.task2027;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/*
Word search

*/

public class Solution {
public static void main(String[] args) {

int[][] wordSearch = new int[][]{
{'f', 'd', 'e', 'r', 'l', 'k'},
{'u', 's', 'a', 'm', 'e', 'o'},
{'l', 'n', 'g', 'r', 'o', 'v'},
{'m', 'l', 'p', 'r', 'r', 'h'},
{'p', 'o', 'e', 'e', 'j', 'j'}
};

detectAllWords(wordSearch, "home", "same");
/*
Expected result
home - (5, 3) - (2, 0)
same - (1, 1) - (4, 1)
*/
}

public static List<Word> detectAllWords(int[][] wordSearch, String... words) {
List<Word> result = new ArrayList<>();

// x and y Size of the wordSearch array
int xLength = wordSearch.length - 1;
int yLength = wordSearch[0].length - 1 ;

// Size of words. It gives us the number of searched words
int nWords = words.length - 1;
// array to load the word Char Array
char[] wordSearched;
// var to check if all the searched words have been found
int wordsFound = 0;
// First xPos of the wordSearch
int xPos;
// Last yPos of wordSearch
int yPos;

// Last position of y coord
int lastYPos;
// Last position of x coord
int lastXPos;
// To get control on movement on diagonal movements
int initXPos;
int initYPos;

// var to check if we have found one word
boolean found = false;

for(String word : words) {
wordSearched = word.toCharArray();
while (wordsFound < nWords){
char[] buffer = new char[xLength];

/*
********************************
*1.- Search from left to right
********************************
*/

xPos = 0;
yPos = 0;

do {
do{
lastYPos = yPos;
for(int index = 0; index < buffer.length; index++){
buffer[index] =(char) wordSearch[xPos][lastYPos];
lastYPos++;
}
lastYPos--;
if(Objects.deepEquals(buffer, wordSearched)){
Word nWord = new Word(word);
nWord.setStartPoint(xPos, yPos);
nWord.setEndPoint(xPos, lastYPos);
wordsFound++;
found = true;
}
yPos ++;
}while(lastYPos < yLength && !found);
xPos++;
yPos = 0;
} while ((xPos <= xLength) && !found);
// If we have already found all the searched words we exit the loop
if (wordsFound == nWords){
break;
}

/*
********************************
*2.-Search from right to left
********************************
*/

yPos = yLength;
xPos = 0;
do{
do{
lastYPos = yPos;
for(int index = 0; index < buffer.length; index++){
buffer[index] = (char) wordSearch[xPos][lastYPos];
lastYPos--;
}
lastYPos++;
if(Objects.deepEquals(buffer, wordSearched)){
Word nWord = new Word(word);
nWord.setStartPoint(xPos, yPos);
nWord.setEndPoint(xPos, lastYPos);
wordsFound++;
found = true;
}
yPos--;
}while(lastYPos > 0 && !found);
xPos++;
yPos = yLength;
}while(xPos <= xLength && !found);

// If we have already found all the searched words we exit the loop
if (wordsFound == nWords){
break;
}

/*
********************************
*3.-Search from top to bottom
********************************
*/
xPos = 0;
yPos = 0;
do{
do{
lastXPos = xPos;
for(int index = 0; index < buffer.length; index++){
buffer[index] =(char) wordSearch[lastXPos][yPos];
lastXPos++;
}
lastXPos--;

if(Objects.deepEquals(buffer, wordSearched)){
Word nWord = new Word(word);
nWord.setStartPoint(xPos, yPos);
nWord.setEndPoint(lastXPos, yPos);
wordsFound++;
found = true;
}
xPos++;
}while(lastXPos < xLength && !found);
yPos++;
xPos = 0;
}while(yPos <= yLength && !found);
// If we have already found all the searched words we exit the loop
if (wordsFound == nWords){
break;
}

/*
********************************
*4.-Search from bottom to top
********************************
*/
xPos = xLength;
yPos = 0;
do{
do {
lastXPos = xPos;
for (int index = 0; index < buffer.length; index++) {
buffer[index] = (char) wordSearch[lastXPos][yPos];
lastXPos--;
}
lastXPos++;

if(Objects.deepEquals(buffer, wordSearched)){
Word nWord = new Word(word);
nWord.setStartPoint(xPos, yPos);
nWord.setEndPoint(lastXPos, yPos);
wordsFound++;
found = true;
}

xPos--;
}while(lastXPos > 0 && !found);
yPos++;
xPos = xLength;
}while(yPos <= yLength && !found);
// If we have already found all the searched words we exit the loop
if (wordsFound == nWords){
break;
}

/*
********************************
5.-Search from left-top to right-bottom
********************************
*/
xPos = 0;
yPos = 0;
initXPos = xPos;
initYPos = yPos;
do{
do{
lastXPos = xPos;
lastYPos = yPos;
//
if((xPos + buffer.length - 1) <= xLength ||
(yPos + buffer.length - 1) <= yLength){
for(int index = 0; index < buffer.length; index++){
buffer[index] =(char) wordSearch[lastXPos][lastYPos];
lastXPos++;
lastYPos++;
}
}
lastXPos--;
lastYPos--;

xPos++;
yPos++;

}while(lastYPos < yLength && !found);

if(lastXPos == xLength){
initXPos = 0; initYPos++;
} else {
initXPos ++; initYPos = 0;
}
xPos = initXPos;
yPos = initYPos;

}while(initXPos < xLength && !found);

/*
********************************
5.-Search from right-bottom to left-top
********************************
*/

/*
********************************
6.-Search from right-top to left-bottom
********************************
*/

/*
********************************
7.-Search from left-bottom to right-top
********************************
*/

}
}
return result;
}

public static class Word {
private String text;
private int startX;
private int startY;
private int endX;
private int endY;

public Word(String text) {
this.text = text;
}

public void setStartPoint(int i, int j) {
startX = i;
startY = j;
}

public void setEndPoint(int i, int j) {
endX = i;
endY = j;
}

@Override
public String toString() {
return String.format("%s - (%d, %d) - (%d, %d)", text, startX, startY, endX, endY);
}
}
}``````
I think that points 1, 2, 3 and 4 are working with no problems but I'm stuck in point 5 and I'm not able to follow. Thanks in advance for some help. **********************************************************************************************************