Skip to content

Instantly share code, notes, and snippets.

/**
A Maze is given as N*N binary matrix of blocks where source block is the upper left most block i.e., maze[0][0] and destination block is lower rightmost block i.e., maze[N-1][N-1]. A rat starts from source and has to reach destination. The rat can move only in two directions: forward and down.
In the maze matrix, 0 means the block is dead end and 1 means the block can be used in the path from source to destination. Note that this is a simple version of the typical Maze problem. For example, a more complex version can be that the rat can move in 4 directions and a more complex version can be with limited number of moves.
**/
#include <iostream>
#include <vector>
bool isSafe(vector<vector<int>> &board, int row, int col) {
// indicates if the next move is legal.
if (row<0 || col <0 || row>=board.size() || col >= board[0].size() || (board[row][col] == 0))
/*
Given a 2D board and a list of words from the dictionary, find all words in the board.
Each word must be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once in a word.
For example,
Given words = ["oath","pea","eat","rain"] and board =
[
['o','a','a','n'],
@pradeep1288
pradeep1288 / isomorphic.cpp
Created February 23, 2016 06:02
Isomorphic Strings.
/*
Given two strings s and t, determine if they are isomorphic.
Two strings are isomorphic if the characters in s can be replaced to get t.
All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character but a character may map to itself.
For example,
Given "egg", "add", return true.
import java.io.*;
import java.util.*;
/**
* Created with IntelliJ IDEA.
* User: pradeepnayak
* Date: 28/03/14
* Time: 3:27 PM
* To change this template use File | Settings | File Templates.
*/
import java.io.*;
import java.util.*;
/**
* Created with IntelliJ IDEA.
* User: pradeepnayak
* Date: 28/03/14
* Time: 3:27 PM
* To change this template use File | Settings | File Templates.
*/
@pradeep1288
pradeep1288 / tsp.java
Created February 28, 2014 08:36
AI Assignment 2 - Completed
import java.io.*;
import java.util.*;
public class tsp {
public static void main(String[] args) throws IOException{
int taskNumber = Integer.parseInt(args[1]);
Graph g = new Graph();
buildShortestPathGraph(g,taskNumber,args);
import java.io.*;
import java.util.*;
/**
* Created with IntelliJ IDEA.
* User: pradeepnayak
* Date: 23/02/14
* Time: 3:45 PM
* To change this template use File | Settings | File Templates.
@pradeep1288
pradeep1288 / tsp.java
Created February 26, 2014 09:11
Assignment 2 - AI
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;
/**
* Created with IntelliJ IDEA.
* User: pradeepnayak
from 'A' to 'B'
-----------------------------------------------
x,y,g,h,f
1,15,0.0,11.0,11.0
1,14,1.0,10.0,11.0
1,13,2.0,9.0,11.0
1,12,3.0,8.0,11.0
1,11,4.0,7.0,11.0
1,10,5.0,6.0,11.0
1,9,6.0,5.0,11.0
from 'A' to 'B'
---------------------------------------------
x,y,g,h,f
15,15,0,14,14
15,14,1,13,14
15,13,2,12,14
15,12,3,11,14
15,11,4,10,14
15,10,5,9,14
15,9,6,8,14