instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
In JavaScript, create a function that returns the length of a string. However, you are not allowed to use the built-in `length` property or any other built-in methods such as `split()`, `slice()`, or `substr()` to calculate the length. You must implement your own logic to count the characters in the string. | codefeedback |
Create a function to generate Fibonacci numbers less than 100, but with the following additional constraints:
1. The function should accept a parameter 'n' which represents the upper limit of the Fibonacci numbers to be generated.
2. The function should return a list of Fibonacci numbers less than 'n'.
3. The function ... | codefeedback |
Create a React component for a Postcard element to display on a webpage.
The postcard should contain a paragraph element containing the text "Hello from Paris!", an image of the Eiffel Tower, and a "Return to Homepage" button below the image.
In addition, the postcard should have a "Share on Facebook" button that, whe... | codefeedback |
Write a script that inputs a list of strings and converts the list into a dictionary, where the keys are the strings and the values are the lengths of the strings.
Example:
Input: ["ABC", "XYZ", "PQR"]
Output: {"ABC": 3, "XYZ": 3, "PQR": 3}
Requirements:
- The script should have a time complexity of O(n), where n is ... | codefeedback |
Write code to output the sum of all prime numbers between 1 and 100. | codefeedback |
Extract all instances of a specific word in the given text, but only if the word is enclosed within parentheses.
Text: The quick (brown) fox jumps over the (lazy) dog.
Word: j | codefeedback |
Suggest a way to create a singly linked list in python, where each node has a data value and a pointer to the next node, and implement a method to reverse the linked list iteratively. | codefeedback |
Create a binary heap sort algorithm in Java that has a time complexity of O(n log n) and a space complexity of O(1). | codefeedback |
How would you create an API endpoint that returns a list of users and their associated posts? | codefeedback |
Create a MongoDB query that retrieves all the documents whose 'name' field contains the given string, ignoring case sensitivity and also including documents whose 'name' field is an exact match of the given string. | codefeedback |
You are given a text and the task is to output each individual word in the text along with its character count. Additionally, you need to remove any punctuation marks from the text before processing it.
Text: "Hello, how are you doing?"
Expected Output:
- Word: "Hello", Character Count: 5
- Word: "how", Character Cou... | codefeedback |
Write a code to print the largest element of an array if the array contains all negative numbers. The array should also not contain any duplicate elements. The code should run in O(n) time complexity. arr = [-10, -20, -50, -30] | codefeedback |
Create a function that prints the binary representation of a decimal number in reverse order.
number = 5 | codefeedback |
Create a C program that prints all distinct combinations of characters from two given strings, where the first string must contain at least one uppercase letter and the second string must contain at least one special character (!@#$%^&*). Additionally, the program should output the combinations in reverse order.
Stri... | codefeedback |
Write a function to merge two sorted lists into one sorted list, using only recursion and without using any built-in sorting functions or data structures. The input lists are guaranteed to be non-empty and contain only positive integers.
list1 = [1, 3, 5, 7]
list2 = [2, 4, 6, 8]
The function should return a single li... | codefeedback |
Given an input of numbers, sort the numbers in descending order using a custom sorting algorithm that is not built-in or commonly used in programming languages. | codefeedback |
Develop an Angular application that displays the current date and time in multiple time zones. | codefeedback |
Write a function called `remove_duplicates` that takes in a list of integers and removes any duplicate elements, while maintaining the order of the elements.
Your function should return the modified list.
Example:
Input: [3, 1, 7, 5, 3, 8, 7]
Output: [3, 1, 7, 5, 8]
Note:
- You should not use any built-in Python f... | codefeedback |
Suggest a better algorithm than Bubble sort for sorting a large array, while also considering memory efficiency and time complexity. Additionally, provide a piece of code that showcases the erroneous implementation of the suggested algorithm to increase the complexity of the question. | codefeedback |
Explain how to calculate the mean value of a function defined from 0 to infinity, considering that the function must be differentiable and bounded. | codefeedback |
Write a code to shuffle a list randomly in Python without using any built-in functions or libraries. The code should have a time complexity of O(n) and should not use any additional space beyond the input list. | codefeedback |
Create a C++ program to merge two arrays of different lengths, but the merged array should contain only unique elements. | codefeedback |
Suggest a data structure for storing a collection of countries and their corresponding population, ensuring efficient retrieval of the top 5 most populous countries based on population. | codefeedback |
Write a SQL query to count how many students are in each grade, where the grade is greater than or equal to 60 and less than or equal to 100. | codefeedback |
Create a shell script to list all available printer models. The script should only display models that have a print speed of at least 30 pages per minute. | codefeedback |
Write a JSON parser to read the following data and output it in a 3-column table. Each column must have a maximum width of 20 characters. The table must be sorted in descending order based on the length of the values in the "name" column. Additionally, the program should handle nested JSON objects and arrays by display... | codefeedback |
Create a Python script that calculates the surface area of a cylinder, but without using the built-in mathematical functions such as pi.
Constraints:
- The script should not use the pi constant from the math module.
- The script should only use basic mathematical operations such as addition, subtraction, multiplicatio... | codefeedback |
Determine the maximum number of nodes in a height-balanced binary tree of height h, where each node has at least 2 children.
h = 4 | codefeedback |
Design a JavaScript function to filter out the prime numbers from an array. The function should have a time complexity of O(n√m), where n is the length of the input array and m is the maximum number in the array.
Example input: [10, 15, 7, 12, 17, 20]
Example output: [7, 17] | codefeedback |
Suggest a better data structure that can be used to store a large amount of data in a way that querying data is fast. Additionally, provide an example of erroneous code that could be used when implementing this data structure, and explain how it could potentially cause issues. | codefeedback |
Generate a SQL query for finding the names of all employees in the company who have been employed for more than 5 years and have received a performance rating of at least 4 in the last year. | codefeedback |
Can you modify the program so that it prints out all words in the sentence along with their count, excluding any words that contain a specific letter? The specific letter will be provided as an input to the program. "The quick brown fox jumped over the lazy dog." | codefeedback |
Generate a program to reverse a string and remove all the white spaces from the string, while also ensuring that the program is case-sensitive and can handle special characters. The program should handle strings of any length and provide an efficient solution with a time complexity of O(n). | codefeedback |
Suggest an efficient method to convert a given array of size N into a min-heap, where N can be up to 10^6. The time complexity of the algorithm should be O(N), and the space complexity should be O(1). | codefeedback |
Change the following code to reduce its running time by using binary search algorithm and assuming the input array 'nums' is sorted in ascending order. If the target is not found, return -1. | codefeedback |
Generate a code to capitalize the first letter of each word of a given sentence while also removing any duplicate words from the sentence.
text = "This is a sample sentence. This is another sample sentence." | codefeedback |
Write code to count the number of times a given pattern has occurred in a given string. The pattern can contain special characters and can be case-sensitive.
Text: "This is a test string to practice coding. This string contains the pattern 'Is'." | codefeedback |
Create a Tableau script to retrieve data from an Amazon RDS instance while ensuring that the data is filtered based on a specific date range and sorted in descending order of a numeric column. | codefeedback |
Write a C++ program to sort an array in ascending and descending order. The program should also remove any duplicate elements in the array before sorting. The array should have at least 10 elements and the program should handle arrays with up to 100 elements. The program should output the sorted array in ascending orde... | codefeedback |
Write a Ruby script that converts a given temperature in degree Celsius to Fahrenheit, using the formula: Fahrenheit = (Celsius * 9/5) + 32.
You should validate that the input is a valid floating-point number, and handle any invalid input gracefully by displaying an error message and allowing the user to retry enterin... | codefeedback |
Generate random numbers 0 to 1000 without using any built-in random number generator functions or libraries. | codefeedback |
Create a function in Java that takes in an array of numbers and calculates the sum of all the prime numbers in the array.
[2, 3, 4, 5, 6, 7, 8, 9, 10, 11] | codefeedback |
Match the strings "string1" and "string2" using regex.
string1="Hello World" and string2="Hello*World".
The expected output should be True if the pattern in string2 matches string1 and False otherwise.
Note: The pattern in string2 can contain any valid regular expression syntax. | codefeedback |
Implement a function to insert an element into a balanced binary search tree.
tree =
5
/ \
2 8
/ \
1 3
Note: The balanced binary search tree should maintain the AVL tree property, where for every node, the difference between the heights of its left and right subtrees is at most 1. | codefeedback |
You have to read a set of numbers and report the number of positive numbers, while also keeping track of the average of all the positive numbers. Additionally, you need to find the maximum and minimum positive numbers in the set.
Constraints:
- The set of numbers can contain up to 10^6 elements.
- Each element in the... | codefeedback |
Given two strings str1 and str2, write a function in JavaScript to check if str1 is a non-overlapping substring of str2. The function should also check for case sensitivity and handle white spaces. | codefeedback |
Edit the following PHP code to return the modular exponentiation of two numbers using the repeated squaring method.
function mod_exp(base, exponent, modulus){
if (modulus == 1)
return 0;
$result = 1;
$base = $base % $modulus;
while ($exponent > 0){
if ($exponent % 2 == 1)
... | codefeedback |
Implement a search() function that uses binary search to find the index of a given element in a sorted array. If the element is not present in the array, return -1. | codefeedback |
Create a function to retrieve a random element from a given list in Java, but the random element must meet the following criteria:
- It must be an odd number greater than 100. | codefeedback |
Build a SQL query to calculate the average salary of employees in each department, excluding any departments that have less than 5 employees. | codefeedback |
Create a bash shell script that will print all prime numbers between 1 and 1000. | codefeedback |
Using C++, unroll the following loop and vectorize the code. Additionally, ensure that the program handles cases where the size of the vectors is not a multiple of the vector size, by padding the vectors appropriately. Finally, optimize the code by utilizing SIMD instructions to perform the vectorized calculations effi... | codefeedback |
Create a HTML form to submit a text entry and view it after submission. Additionally, implement client-side validation to check if the text entry is a valid email address before submission. | codefeedback |
Generate a JavaScript code that prints all the prime numbers from 1 to 1000. | codefeedback |
Set an environment variable in Bash that holds the value of the given string, but the variable name must start with a lowercase letter and contain at least one digit. The string must be at least 8 characters long and contain at least one uppercase letter, one lowercase letter, one digit, and one special character (e.g.... | codefeedback |
Construct a HTML page for a registration form that includes the following additional requirements:
1. The form must include at least five different input fields, such as text, email, password, radio buttons, checkboxes, etc.
2. Implement form validation to ensure that all required fields are filled out and that the em... | codefeedback |
Create a Javascript function that calculates the median value of an array of numbers. The function should have a time complexity of O(n log n) or better. The input array can contain duplicates, negative numbers, and can be unsorted. The function should return the median value as a floating-point number. If the input ar... | codefeedback |
Reformat a given JSON string between quotes to a properly indented and formatted output. The solution should have a time complexity of O(n), where n is the length of the input string.
Example:
Input: "{\"menu\":{\"id\":\"file\",\"value\":\"File\",\"popup\":{\"menuitem\":[{\"value\":\"New\", \"onclick\":\"CreateNewDoc(... | codefeedback |
Convert the following HTML table into a valid JSON format. Additionally, each value in the JSON should be converted to uppercase. | codefeedback |
Modify the code to convert any temperature from Celsius to Fahrenheit, but without using the multiplication operator. | codefeedback |
Write a JavaScript program to request a user's name and display a greeting message with the user's name, while ensuring that the user's name is at least 10 characters long and contains at least one uppercase letter and one special character. | codefeedback |
Create a function that joins two strings into one, but the strings must be reversed before being joined. | codefeedback |
Design and implement a function that takes two lists of integers as parameters and returns the minimum absolute difference between two elements of the two lists. The absolute difference between two integers a and b is given by |a - b|.
list1 = [2, 4, 7, 13]
list2 = [3, 8, 9, 14]
#Erroneous Code#
list1 = [2, 4, 7, 13]... | codefeedback |
Given the following HTML code, write a CSS rule to change the font size to 12px only for the first paragraph element with the class "text" that is directly preceded by a heading element with the class "heading". Otherwise, the font size should remain unchanged.
<h1 class="heading">Title</h1>
<p class="text">Test</p> | codefeedback |
Find the longest substring with non-repeating characters in a given string.
You should handle cases where the string is empty or contains only one character.
Your solution should be efficient and have a time complexity of O(n), where n is the length of the string. | codefeedback |
Construct a C# program to display the Fibonacci series up to the nth term, where n is a prime number. | codefeedback |
Construct a function that takes a decimal number as input and converts it to a binary string.
Input: 15
Additional requirements:
1. You are not allowed to use any built-in functions or libraries for converting decimal to binary.
2. The function should handle both positive and negative decimal numbers.
3. The function ... | codefeedback |
Write a loop in Python to find all prime numbers below 100. | codefeedback |
Implement a supervised learning algorithm from scratch in Python without using any external libraries. The algorithm should be able to handle both binary and multi-class classification problems. Provide detailed explanations of each step in the algorithm and the rationale behind your choices. | codefeedback |
Create a SQL query that combines three tables ``A``, ``B``, and ``C``.
Table A
id name
1 car
2 bike
Table B
id owner
1 Sam
2 John
Table C
id location
1 garage
2 shed
The query should join the three tables on their respective IDs and display the following columns: ``A.name``, ``B.owner``, and `... | codefeedback |
Suggest a suitable type of machine learning algorithm for the following task.
Identifying the sentiment of a movie review, but also take into consideration the review's context and the reviewer's personal biases. Additionally, the algorithm should be able to handle large datasets with high dimensionality efficiently. | codefeedback |
Write a SQL query to count the number of distinct records with a field of "user_id" in the table called "users", where the user_id is greater than 1000 and the user's country is not in a predefined list of banned countries (e.g., USA, China, Russia). | codefeedback |
Design a program to partition an array into two subarrays such that the difference between the sum of the two subarrays is minimum.
Input Array: [1, 6, 5, 11, 3, -2, 8, 4, 9, -5]
Provide a piece of erroneous code as a reference to increase misdirection:
```
def partition_array(array):
n = len(array)
total_sum ... | codefeedback |
Create a function that will take a string as an input and returns the number of upper case letters in it. However, you must implement this function without using any built-in string methods or functions that directly check for upper case letters (e.g. isupper()). | codefeedback |
Create a list containing the prime numbers from #1 to #10. | codefeedback |
Edit the program to simulate a game of poker. The program should allow the user to enter the number of players and deal a random hand of 5 cards to each player. The program should then evaluate each player's hand and determine the winner based on standard poker hand rankings (e.g. straight flush, four of a kind, full h... | codefeedback |
What is the sum of all the even numbers in the range 1-1000 inclusive? | codefeedback |
Write a JavaScript program that asks the user to enter a positive integer and then prints the sum of the cube of the digits of the number. The program should also check if the entered number is greater than 0 and less than or equal to 10^9. If the number does not meet these requirements, the program should display an e... | codefeedback |
How would you flatten a two dimensional list while ignoring any duplicate elements?
#Erroneous Code#
Provide a piece of code that attempts to flatten the list but fails to remove duplicate elements. | codefeedback |
Create a function which takes in a string and returns a dictionary that counts its character frequency. Additionally, handle any erroneous inputs such as empty strings or non-string inputs by raising appropriate exceptions. | codefeedback |
What do you need to do to print the element at the index 5 in a 2D array? | codefeedback |
Generate a five digit random string that contains only uppercase letters and digits. | codefeedback |
Write a program that can generate the first N prime numbers, where N is provided as user input. | codefeedback |
Explain the effect of calling the following JavaScript function on the list provided.
list = [4,8,2,7];
function sort_ascending(list) {
list.sort(function(a, b){return a-b});
}
What is the time complexity of the sort_ascending function? | codefeedback |
Given a binary tree, write a function to serialize and deserialize the tree.
Serialize the tree by converting it into a string representation where each node is represented by its value and the null nodes are represented by '#'. The serialized string should be such that it can be deserialized back into the original bi... | codefeedback |
Name a data structure that allows efficient insertion and deletion of elements at the beginning, middle and end. Additionally, provide a code snippet that demonstrates the correct implementation of the data structure, but contains a logical error that needs to be fixed. | codefeedback |
How can you find the maximum element in an array using the reduce() method while ensuring that the array contains at least 10 elements and that the maximum element is greater than or equal to 100? | codefeedback |
Create a Java class that defines a circle with the following requirements:
1. The class should have two double data fields, radius and area.
2. The radius should be a positive number greater than 0.
3. The area should be calculated using the formula A = π * r^2, where A is the area and r is the radius.
4. The area sho... | codefeedback |
Create a function that takes in two numbers, a numerator and a denominator, and returns the result of the division expressed as a float. However, you are not allowed to use the division operator (/) or any built-in functions that perform division.
Example:
Input: numerator = 10, denominator = 20
Output: 0.5 | codefeedback |
Create an API using Django Rest Framework to retrieve data from a PostgreSQL database table. The API should include the following features:
1. Authentication: Implement token-based authentication using Django Rest Framework's built-in authentication classes. Only authenticated users should be able to access the API.
... | codefeedback |
Create a program to print out all twin prime numbers below 10,000. Twin primes are prime numbers that differ by 2, such as (3, 5), (11, 13), (17, 19), and so on. | codefeedback |
Given an array, arrange the elements in order without using any built-in sorting functions.
arr = [3, 7, 2, 1, 5]
Additional constraint: The time complexity of the solution should be O(n^2) or better. | codefeedback |
You need to design a calculator class with methods to perform basic calculations (add, subtract, multiply, divide, etc.). However, the calculator should only allow operations on positive integers and should throw an exception if any negative numbers or non-integer values are passed as arguments. Additionally, the calcu... | codefeedback |
Construct a SQL query to select the names of all people aged between 21 and 30 years, whose names start with the letter 'J' and have at least 3 vowels in their name.
Table Schema:
table_person(p_id int, p_name varchar, p_age int) | codefeedback |
Design a data structure to store an undo history of size k, where each undo operation must be completed in constant time complexity. Additionally, ensure that the undo history supports multiple data types, including integers, strings, and objects, and can handle a maximum of n undo operations per second. | codefeedback |
Write an SQL query to return the names of workers whose salary is within the top 10% among all workers.
Table Schema:
table_workers(id int, name varchar, salary int) | codefeedback |
Create a function in Python that generates a Fibonacci sequence of n numbers. The function should take an integer n as input and return a list of the Fibonacci sequence. The Fibonacci sequence should start with 0 and 1, and each subsequent number in the sequence should be the sum of the two previous numbers.
Example:
... | codefeedback |
In JavaScript, construct a function to obtain the number of digits in a given integer. However, you must not use the built-in functions such as `toString()` or `length` to solve this problem. | codefeedback |
Create a function in Python to rearrange the characters of each word in a given string, without using any built-in string manipulation functions or libraries. The input string will only contain alphabetic characters and spaces. The function should handle uppercase and lowercase letters properly. The rearranged words sh... | codefeedback |
Develop a script in Perl to sort an array in descending order, without using any built-in sorting functions. The array should only contain unique integers between 1 and 100. Your script should also print the second largest element in the sorted array. arr = (11, 12, 4, 15, 6) | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.