Salesforce Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Written Test




Comment hidden because of low score. Click to expand.
1
of 1 vote

package salesForceCodingProblems;

import java.util.ArrayList;

public class DFTreeNode {

	private String nodeName;
	private ArrayList<DFTreeNode> childrenNodes;
	private boolean isRoot, isFile;
	private String permissions;
	private DFTreeNode parent;

	public DFTreeNode(String name, boolean isRoot, boolean isFile, String permission, DFTreeNode parentNode)
			throws Exception {
		// TODO Auto-generated constructor stub
		this.nodeName = name;
		if (isRoot && isFile) {
			Exception ex = new Exception("Invalid Operation!!! One entity can't be a root directory as well as a file.");
			throw ex;
		}
		this.isFile = isFile;
		this.isRoot = isRoot;
		if (isRoot)
			this.parent = null;
		else
			this.parent = parentNode;
		this.childrenNodes = new ArrayList<DFTreeNode>();
		this.permissions = permission;
	}

	public String getName() {
		return this.nodeName;
	}

	public boolean isRootFolder() {
		return this.isRoot;
	}

	public boolean isTypeFile() {
		return this.isFile;
	}

	public String getPermissions() {
		return this.permissions;
	}

	public DFTreeNode getParent() {
		return this.parent;
	}

	public void setPermissions(String newPermissions) {
		this.permissions = newPermissions;
	}

	public void setRoot() throws Exception {
		if (this.isFile) {
			Exception ex = new Exception("Invalid Operation!!! This is a file. You can't set root directory to a file.");
			throw ex;
		}
		this.isRoot = true;
		this.parent = null;
	}

	public void setTypeFile() throws Exception {
		if (this.childrenNodes != null) {
			Exception fileEx = new Exception("Invalid Operation!!! This is a directory and has children. You can't a file type to a directory.");
			throw fileEx;
		}
		this.isFile = true;
	}

	public void addChild(DFTreeNode tn) throws Exception {
		if (this.isFile) {
			Exception fileEx = new Exception("Invalid Operation!!! This is a file. You can't add child to a file type.");
			throw fileEx;
		}
		childrenNodes.add(tn);
	}

	public DFTreeNode getChild(String childName) throws Exception {
		if (!this.childrenNodes.isEmpty()) {
			for (DFTreeNode childNode : this.childrenNodes) {
				if (childNode.getName().equals(childName))
					return childNode;
			}
		}

		Exception childNotFoundEx = new Exception(childName + " is not present in this directory.");
		throw childNotFoundEx;
	}

	public void printChildren(boolean details) {
		if (details) {
			for (DFTreeNode cdf : childrenNodes) {
				String end = "";
				if (!cdf.isFile)
					end = "/";
				System.out.println(" " + cdf.getPermissions() + " " + cdf.getName() + end);
			}
		} else {
			for (DFTreeNode cdf : childrenNodes) {
				String end = "";
				if (!cdf.isFile)
					end = "/";
				System.out.print(" " + cdf.getName() + end);
			}
		}
	}
}


package salesForceCodingProblems;

import java.util.Scanner;

public class CLI {

	static DFTreeNode currentDir, rootDirectory;
	static final String defaultPermissions = "rwxrwxrwx";

	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub

		try {
			rootDirectory = new DFTreeNode("/", true, false, "rwxrwxrwx", null);
			currentDir = rootDirectory;
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}

		parseInput();
	}

	private static void parseInput() {
		System.out.print(": ");
		Scanner scInput = new Scanner(System.in);
		String inputStr = scInput.nextLine();
		//
		// System.out.println("Command -> " + inputStr + " ");

		if (!inputStr.equals("exit")) {
			parseCommand(inputStr);
			parseInput();
		}
	}

	private static void parseCommand(String cmd) {
		String[] cmdParts = cmd.split(" ");
		switch (cmdParts[0]) {
		case "ls":
			lsCommand(cmdParts);
			break;

		case "pwd":
			pwdCommand();
			break;

		case "cd":
			cdCommand(cmdParts);
			break;

		case "mkdir":
			mkdirCommand(cmdParts);
			break;

		case "vi":
			viCommand(cmdParts);
			break;

		default:
			System.out.println("Invalid command " + cmd);
		}
	}

	private static void lsCommand(String[] cmdArray) {
		if (cmdArray.length == 1)
			currentDir.printChildren(false);
		else
			currentDir.printChildren(true);
	}

	private static void pwdCommand() {

		DFTreeNode tempParentNode = currentDir.getParent();
		String path = currentDir.getName();
		while (tempParentNode != null) {
			path = tempParentNode.getName() + "'/'" + path;
			tempParentNode = tempParentNode.getParent();
		}

		System.out.println(path);
	}

	private static void viCommand(String[] cmdArray) {
		if (cmdArray.length == 1)
			System.out.println("Invalid VI command. Enter filename.");
		else
			try {
				String permission = defaultPermissions;
				if (cmdArray.length > 2)
					permission = cmdArray[2];
				currentDir.addChild(new DFTreeNode(cmdArray[1], false, true, permission, currentDir));
			} catch (Exception e) {
				e.printStackTrace();
			}
	}

	private static void mkdirCommand(String[] cmdArray) {
		if (cmdArray.length == 1)
			System.out.println("Invalid mkdir command. Enter directory name.");
		else
			try {
				String permission = defaultPermissions;
				if (cmdArray.length > 2)
					permission = cmdArray[2];
				currentDir.addChild(new DFTreeNode(cmdArray[1], false, false, permission, currentDir));
			} catch (Exception e) {
				e.printStackTrace();
			}
	}

	private static void cdCommand(String[] cmdArray) {
		if (cmdArray.length == 1)
			System.out.println("Invalid cd command.");
		else
			try {

				switch (cmdArray[1]) {
				case "/":
					currentDir = rootDirectory;
					break;

				case "..":
					currentDir = currentDir.getParent();
					break;

				default:
					currentDir = currentDir.getChild(cmdArray[1]);
					break;
				}

			} catch (Exception e) {
				System.out.println(e.getMessage());
			}
	}
}

- KunalP February 29, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

file systems are commonly implemented using a b-tree

- danbuscaglia March 04, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Its probably not b-tree, rather n-ary tree.

- uday May 29, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

ya?
The core data structure of Btrfs — the copy-on-write B-tree — was originally proposed by IBM researcher Ohad Rodeh at a presentation at USENIX 2007. Chris Mason, an engineer working on ReiserFS for SUSE at the time, joined Oracle later that year and began work on a new file system based on these B-trees

- danbuscaglia May 29, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Is it to simulated the commands like "LS PWD and CD" or create a new file system altogether ??

- am October 08, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can anyone comment as to how the remote programming assignment went? Can you use your own environment? Do they watch you for the whole 2-hours? Thanks!

- acj November 12, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Did you get the answer how it went? Would be helpful to know.

- Rohit July 18, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 2 votes

2 hour Online Coding Test - They gave a sample frame code having 4 methods -> Makefriends(), removeFriends(), getDirectFriends(), getIndirectFriends(). Have to implement these methods. Also create unit testcases to check conditions.
Have to build on the frame sample code they provide and send back the zip implementation in 90 mins. Then they will call back to discuss the logic.

- payal July 22, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

i just took the same test at salesforce. the interviewer calls you ahead talks to you for 10 mins or so, makes sure you understand the problem statement correctly..
after that, you can use the editor of your choice to implement the solution.. and when you are done, just email the program/project to the interviewer.

- sss December 06, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Did you receive the same question with this? It seems this question is about implementing a kind of shell rather than file system, doesn't it?

- sales December 12, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Writing a b-tree implementation may take more than 2 hours ..

Would it be OK to write a list- based implementation of the shell or should it be B-Tree .

c# does not have a good library APi for B-Tree or balanced trees.

- hub&spoke January 06, 2015 | Flag
Comment hidden because of low score. Click to expand.
2
of 2 votes

2 hour Online Coding Test -
They gave a sample frame code having 4 methods -> Makefriends(), removeFriends(), getDirectFriends(), getIndirectFriends(). Have to implement these methods. Also create unit testcases to check conditions.
Have to build on the frame sample code they provide and send back the zip implementation in 90 mins. Then they will call back to discuss the logic.

- payal July 22, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@payal:

what do these methods do? are they similar to adding/removing facebook/linkedin relationships?

- codewarrior August 08, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

This will require N+ tree to represent Directory

public class Node {
public string nodeName { get; set; }
List<Nodes> ChildNodes {get; set; }
public FileType fileType {get; set;}
public Stream dataFile { get; set; }

// constr
Node(string nodename, List<Node> nodes, FileType fileType, Stream filestream)
{
...
}

}

enum FileType {
text,
data,
folder,
...
}


ICommand {

void Execute(string[] args);

}


public class CommandFactory {

public ICommand GetCommand(Directory dir, string cmd, params string[] args)
{
Validate(cmd ) // validate command

switch(cmd)
{
case "ls" :

return LsCommand( ... );
break;

case "cd" :

return CdCommand(...);
break;

default :
throw error;
break;
}


}


}


main (args ){
// create directory
Node rootDir = new Node();


ICommand cmd = CommandFactory( rootDir, cmd, args);

cmd.Execute();


}


LsCommand {

// constructor

LSCommand( ... , .. .., _ ) {}

void Execute( ,... , ... , ... )
{
/// ls command execution
go over each node and print all names of nodes
// if -l
print only with filetype Directory
}

}

- Megatron February 04, 2015 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More